(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestNewCmdRoot_ExtensionRegistration(t *testing.T) { |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | extensions []string |
| 21 | wantRegistered []string |
| 22 | wantSkipped []string |
| 23 | }{ |
| 24 | { |
| 25 | name: "extension conflicts with core command 'copilot'", |
| 26 | extensions: []string{"copilot"}, |
| 27 | wantSkipped: []string{"copilot"}, |
| 28 | wantRegistered: []string{}, |
| 29 | }, |
| 30 | { |
| 31 | name: "extension does not conflict with any core command", |
| 32 | extensions: []string{"my-custom-extension"}, |
| 33 | wantSkipped: []string{}, |
| 34 | wantRegistered: []string{"my-custom-extension"}, |
| 35 | }, |
| 36 | { |
| 37 | name: "extension that conflicts with a core command's alias", |
| 38 | extensions: []string{"agent"}, |
| 39 | wantSkipped: []string{"agent"}, |
| 40 | wantRegistered: []string{}, |
| 41 | }, |
| 42 | { |
| 43 | name: "multiple extensions with some conflicts", |
| 44 | extensions: []string{"pr", "custom-ext", "issue", "another-ext"}, |
| 45 | wantSkipped: []string{"pr", "issue"}, |
| 46 | wantRegistered: []string{"custom-ext", "another-ext"}, |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | for _, tt := range tests { |
| 51 | t.Run(tt.name, func(t *testing.T) { |
| 52 | ios, _, _, _ := iostreams.Test() |
| 53 | |
| 54 | var extMocks []extensions.Extension |
| 55 | for _, extName := range tt.extensions { |
| 56 | extMocks = append(extMocks, &extensions.ExtensionMock{ |
| 57 | NameFunc: func() string { |
| 58 | return extName |
| 59 | }, |
| 60 | OwnerFunc: func() string { |
| 61 | return "" |
| 62 | }, |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | em := &extensions.ExtensionManagerMock{ |
| 67 | ListFunc: func() []extensions.Extension { |
| 68 | return extMocks |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | f := &cmdutil.Factory{ |
| 73 | IOStreams: ios, |
| 74 | Config: func() (gh.Config, error) { |
nothing calls this directly
no test coverage detected