(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestNewCmdCreate(t *testing.T) { |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | cli string |
| 18 | wants createOpts |
| 19 | wantsErr bool |
| 20 | wantsErrMsg string |
| 21 | wantsExporter bool |
| 22 | }{ |
| 23 | { |
| 24 | name: "title", |
| 25 | cli: "--title t", |
| 26 | wants: createOpts{ |
| 27 | title: "t", |
| 28 | }, |
| 29 | }, |
| 30 | { |
| 31 | name: "owner", |
| 32 | cli: "--title t --owner monalisa", |
| 33 | wants: createOpts{ |
| 34 | owner: "monalisa", |
| 35 | title: "t", |
| 36 | }, |
| 37 | }, |
| 38 | { |
| 39 | name: "json", |
| 40 | cli: "--title t --format json", |
| 41 | wants: createOpts{ |
| 42 | title: "t", |
| 43 | }, |
| 44 | wantsExporter: true, |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | t.Setenv("GH_TOKEN", "auth-token") |
| 49 | |
| 50 | for _, tt := range tests { |
| 51 | t.Run(tt.name, func(t *testing.T) { |
| 52 | ios, _, _, _ := iostreams.Test() |
| 53 | f := &cmdutil.Factory{ |
| 54 | IOStreams: ios, |
| 55 | } |
| 56 | |
| 57 | argv, err := shlex.Split(tt.cli) |
| 58 | assert.NoError(t, err) |
| 59 | |
| 60 | var gotOpts createOpts |
| 61 | cmd := NewCmdCreate(f, func(config createConfig) error { |
| 62 | gotOpts = config.opts |
| 63 | return nil |
| 64 | }) |
| 65 | |
| 66 | cmd.SetArgs(argv) |
| 67 | _, err = cmd.ExecuteC() |
| 68 | if tt.wantsErr { |
| 69 | assert.Error(t, err) |
| 70 | assert.Equal(t, tt.wantsErrMsg, err.Error()) |
| 71 | return |
nothing calls this directly
no test coverage detected