(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestNewCmdConfigList(t *testing.T) { |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | input string |
| 21 | output ListOptions |
| 22 | wantsErr bool |
| 23 | }{ |
| 24 | { |
| 25 | name: "no arguments", |
| 26 | input: "", |
| 27 | output: ListOptions{}, |
| 28 | wantsErr: false, |
| 29 | }, |
| 30 | { |
| 31 | name: "list with host", |
| 32 | input: "--host HOST.com", |
| 33 | output: ListOptions{Hostname: "HOST.com"}, |
| 34 | wantsErr: false, |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | for _, tt := range tests { |
| 39 | t.Run(tt.name, func(t *testing.T) { |
| 40 | f := &cmdutil.Factory{ |
| 41 | Config: func() (gh.Config, error) { |
| 42 | return config.NewBlankConfig(), nil |
| 43 | }, |
| 44 | } |
| 45 | |
| 46 | argv, err := shlex.Split(tt.input) |
| 47 | assert.NoError(t, err) |
| 48 | |
| 49 | var gotOpts *ListOptions |
| 50 | cmd := NewCmdConfigList(f, func(opts *ListOptions) error { |
| 51 | gotOpts = opts |
| 52 | return nil |
| 53 | }) |
| 54 | cmd.Flags().BoolP("help", "x", false, "") |
| 55 | |
| 56 | cmd.SetArgs(argv) |
| 57 | cmd.SetIn(&bytes.Buffer{}) |
| 58 | cmd.SetOut(&bytes.Buffer{}) |
| 59 | cmd.SetErr(&bytes.Buffer{}) |
| 60 | |
| 61 | _, err = cmd.ExecuteC() |
| 62 | if tt.wantsErr { |
| 63 | assert.Error(t, err) |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | assert.NoError(t, err) |
| 68 | assert.Equal(t, tt.output.Hostname, gotOpts.Hostname) |
| 69 | }) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func Test_listRun(t *testing.T) { |
| 74 | tests := []struct { |
nothing calls this directly
no test coverage detected