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