|
| 1 | +package ghmcp |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/github/github-mcp-server/pkg/github" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestTransformDefault(t *testing.T) { |
| 12 | + tests := []struct { |
| 13 | + name string |
| 14 | + input []string |
| 15 | + expected []string |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "empty slice", |
| 19 | + input: []string{}, |
| 20 | + expected: []string{}, |
| 21 | + }, |
| 22 | + { |
| 23 | + name: "default only", |
| 24 | + input: []string{"default"}, |
| 25 | + expected: []string{ |
| 26 | + "context", |
| 27 | + "repos", |
| 28 | + "issues", |
| 29 | + "pull_requests", |
| 30 | + "users", |
| 31 | + }, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "default with additional toolsets", |
| 35 | + input: []string{"default", "actions", "gists"}, |
| 36 | + expected: []string{ |
| 37 | + "actions", |
| 38 | + "gists", |
| 39 | + "context", |
| 40 | + "repos", |
| 41 | + "issues", |
| 42 | + "pull_requests", |
| 43 | + "users", |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "default with overlapping toolsets", |
| 48 | + input: []string{"default", "issues", "actions"}, |
| 49 | + expected: []string{ |
| 50 | + "issues", |
| 51 | + "actions", |
| 52 | + "context", |
| 53 | + "repos", |
| 54 | + "pull_requests", |
| 55 | + "users", |
| 56 | + }, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "no default present", |
| 60 | + input: []string{"actions", "gists", "notifications"}, |
| 61 | + expected: []string{"actions", "gists", "notifications"}, |
| 62 | + }, |
| 63 | + { |
| 64 | + name: "duplicate toolsets without default", |
| 65 | + input: []string{"actions", "gists", "actions"}, |
| 66 | + expected: []string{"actions", "gists"}, |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "duplicate toolsets with default", |
| 70 | + input: []string{"actions", "default", "actions", "issues"}, |
| 71 | + expected: []string{ |
| 72 | + "actions", |
| 73 | + "issues", |
| 74 | + "context", |
| 75 | + "repos", |
| 76 | + "pull_requests", |
| 77 | + "users", |
| 78 | + }, |
| 79 | + }, |
| 80 | + { |
| 81 | + name: "multiple defaults (edge case)", |
| 82 | + input: []string{"default", "actions", "default"}, |
| 83 | + expected: []string{ |
| 84 | + "actions", |
| 85 | + "context", |
| 86 | + "repos", |
| 87 | + "issues", |
| 88 | + "pull_requests", |
| 89 | + "users", |
| 90 | + }, |
| 91 | + }, |
| 92 | + { |
| 93 | + name: "all default toolsets already present with default", |
| 94 | + input: []string{"context", "repos", "issues", "pull_requests", "users", "default"}, |
| 95 | + expected: []string{ |
| 96 | + "context", |
| 97 | + "repos", |
| 98 | + "issues", |
| 99 | + "pull_requests", |
| 100 | + "users", |
| 101 | + }, |
| 102 | + }, |
| 103 | + } |
| 104 | + |
| 105 | + for _, tt := range tests { |
| 106 | + t.Run(tt.name, func(t *testing.T) { |
| 107 | + result := transformDefault(tt.input) |
| 108 | + |
| 109 | + // Check that the result has the correct length |
| 110 | + require.Len(t, result, len(tt.expected), "result length should match expected length") |
| 111 | + |
| 112 | + // Create a map for easier comparison since order might vary |
| 113 | + resultMap := make(map[string]bool) |
| 114 | + for _, toolset := range result { |
| 115 | + resultMap[toolset] = true |
| 116 | + } |
| 117 | + |
| 118 | + expectedMap := make(map[string]bool) |
| 119 | + for _, toolset := range tt.expected { |
| 120 | + expectedMap[toolset] = true |
| 121 | + } |
| 122 | + |
| 123 | + // Check that both maps contain the same toolsets |
| 124 | + assert.Equal(t, expectedMap, resultMap, "result should contain all expected toolsets without duplicates") |
| 125 | + |
| 126 | + // Verify no duplicates in result |
| 127 | + assert.Len(t, resultMap, len(result), "result should not contain duplicates") |
| 128 | + |
| 129 | + // Verify "default" is not in the result |
| 130 | + assert.False(t, resultMap["default"], "result should not contain 'default'") |
| 131 | + }) |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +func TestTransformDefaultWithActualDefaults(t *testing.T) { |
| 136 | + // This test verifies that the function uses the actual default toolsets from GetDefaultToolsetIDs() |
| 137 | + input := []string{"default"} |
| 138 | + result := transformDefault(input) |
| 139 | + |
| 140 | + defaultToolsets := github.GetDefaultToolsetIDs() |
| 141 | + |
| 142 | + // Check that result contains all default toolsets |
| 143 | + require.Len(t, result, len(defaultToolsets), "result should contain all default toolsets") |
| 144 | + |
| 145 | + resultMap := make(map[string]bool) |
| 146 | + for _, toolset := range result { |
| 147 | + resultMap[toolset] = true |
| 148 | + } |
| 149 | + |
| 150 | + for _, defaultToolset := range defaultToolsets { |
| 151 | + assert.True(t, resultMap[defaultToolset], "result should contain default toolset: %s", defaultToolset) |
| 152 | + } |
| 153 | + |
| 154 | + // Verify "default" is not in the result |
| 155 | + assert.False(t, resultMap["default"], "result should not contain 'default'") |
| 156 | +} |
0 commit comments