...

Source file src/github.com/cybertec-postgresql/pgwatch/v3/internal/webserver/cmdoptions_test.go

Documentation: github.com/cybertec-postgresql/pgwatch/v3/internal/webserver

     1  package webserver
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	flags "github.com/jessevdk/go-flags"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestWebDisableOpt(t *testing.T) {
    12  	a := assert.New(t)
    13  	testCases := []struct {
    14  		args        []string
    15  		expected    string
    16  		expectError bool
    17  	}{
    18  		{[]string{0: "config_test"}, "", false},
    19  		{[]string{0: "config_test", "--web-disable"}, WebDisableAll, false},
    20  		{[]string{0: "config_test", "--web-disable=all"}, WebDisableAll, false},
    21  		{[]string{0: "config_test", "--web-disable=ui"}, WebDisableUI, false},
    22  		{[]string{0: "config_test", "--web-disable=foo"}, "", true},
    23  	}
    24  
    25  	for _, tc := range testCases {
    26  		opts := new(CmdOpts)
    27  		os.Args = tc.args
    28  		_, err := flags.NewParser(opts, flags.HelpFlag).Parse()
    29  
    30  		if tc.expectError {
    31  			a.Error(err)
    32  			a.Empty(opts.WebDisable)
    33  		} else {
    34  			a.NoError(err)
    35  			a.Equal(tc.expected, opts.WebDisable)
    36  		}
    37  	}
    38  
    39  }
    40