(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestNewCmdToken(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | input string |
| 19 | output TokenOptions |
| 20 | wantErr bool |
| 21 | wantErrMsg string |
| 22 | }{ |
| 23 | { |
| 24 | name: "no flags", |
| 25 | input: "", |
| 26 | output: TokenOptions{}, |
| 27 | }, |
| 28 | { |
| 29 | name: "with hostname", |
| 30 | input: "--hostname github.mycompany.com", |
| 31 | output: TokenOptions{Hostname: "github.mycompany.com"}, |
| 32 | }, |
| 33 | { |
| 34 | name: "with user", |
| 35 | input: "--user test-user", |
| 36 | output: TokenOptions{Username: "test-user"}, |
| 37 | }, |
| 38 | { |
| 39 | name: "with shorthand user", |
| 40 | input: "-u test-user", |
| 41 | output: TokenOptions{Username: "test-user"}, |
| 42 | }, |
| 43 | { |
| 44 | name: "with shorthand hostname", |
| 45 | input: "-h github.mycompany.com", |
| 46 | output: TokenOptions{Hostname: "github.mycompany.com"}, |
| 47 | }, |
| 48 | { |
| 49 | name: "with secure-storage", |
| 50 | input: "--secure-storage", |
| 51 | output: TokenOptions{SecureStorage: true}, |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | for _, tt := range tests { |
| 56 | t.Run(tt.name, func(t *testing.T) { |
| 57 | ios, _, _, _ := iostreams.Test() |
| 58 | f := &cmdutil.Factory{ |
| 59 | IOStreams: ios, |
| 60 | Config: func() (gh.Config, error) { |
| 61 | cfg := config.NewBlankConfig() |
| 62 | return cfg, nil |
| 63 | }, |
| 64 | } |
| 65 | argv, err := shlex.Split(tt.input) |
| 66 | require.NoError(t, err) |
| 67 | |
| 68 | var cmdOpts *TokenOptions |
| 69 | cmd := NewCmdToken(f, func(opts *TokenOptions) error { |
| 70 | cmdOpts = opts |
| 71 | return nil |
| 72 | }) |
nothing calls this directly
no test coverage detected