@@ -64,26 +64,44 @@ func TestMatch(t *testing.T) {
64
64
}
65
65
66
66
func TestHandler (t * testing.T ) {
67
+ copyEntries := func (m map [string ]* Entry ) map [string ]* Entry {
68
+ out := make (map [string ]* Entry )
69
+ for k , v := range m {
70
+ e := & Entry {
71
+ Primary : v .Primary ,
72
+ }
73
+ if len (v .Secondary ) != 0 {
74
+ e .Secondary = v .Secondary
75
+ }
76
+ out [k ] = e
77
+ }
78
+ return out
79
+ }
80
+
67
81
testCases := []struct {
68
- method string
69
- code int
70
- paths []string
71
- entries map [string ]* Entry
82
+ method string
83
+ code int
84
+ all bool
85
+ paths []string
86
+ entries map [string ]* Entry
87
+ platforms map [string ]* Entry
72
88
}{
73
- {"PUT" , http .StatusMethodNotAllowed , nil , nil },
74
- {"OPTIONS" , http .StatusOK , nil , nil },
89
+ {"PUT" , http .StatusMethodNotAllowed , false , nil , nil , nil },
90
+ {"OPTIONS" , http .StatusOK , false , nil , nil , nil },
75
91
{
76
- "POST" , http .StatusOK ,
92
+ "POST" , http .StatusOK , false ,
77
93
[]string {"nonexistent/path" },
78
94
map [string ]* Entry {"nonexistent/path" : nil },
95
+ nil ,
79
96
},
80
97
{
81
- "POST" , http .StatusOK ,
98
+ "POST" , http .StatusOK , false ,
82
99
[]string {"go/src/archive/zip/a.go" },
83
100
map [string ]* Entry {"go/src/archive/zip/a.go" : {Primary : []Owner {joetsai }, Secondary : []Owner {bradfitz }}},
101
+ nil ,
84
102
},
85
103
{
86
- "POST" , http .StatusOK ,
104
+ "POST" , http .StatusOK , false ,
87
105
[]string {
88
106
"go/src/archive/zip/a.go" ,
89
107
"go/src/archive/zip/b.go" ,
@@ -92,9 +110,22 @@ func TestHandler(t *testing.T) {
92
110
"go/src/archive/zip/a.go" : {Primary : []Owner {joetsai }, Secondary : []Owner {bradfitz }},
93
111
"go/src/archive/zip/b.go" : {Primary : []Owner {joetsai }, Secondary : []Owner {bradfitz }},
94
112
},
113
+ nil ,
114
+ },
115
+ {
116
+ "POST" , http .StatusOK , false ,
117
+ []string {
118
+ "go/src/archive/zip/a.go" ,
119
+ "crypto/chacha20poly1305/chacha20poly1305.go" ,
120
+ },
121
+ map [string ]* Entry {
122
+ "go/src/archive/zip/a.go" : {Primary : []Owner {joetsai }, Secondary : []Owner {bradfitz }},
123
+ "crypto/chacha20poly1305/chacha20poly1305.go" : {Primary : []Owner {filippo , roland , securityTeam }},
124
+ },
125
+ nil ,
95
126
},
96
127
{
97
- "POST" , http .StatusOK ,
128
+ "POST" , http .StatusOK , false ,
98
129
[]string {
99
130
"go/src/archive/zip/a.go" ,
100
131
"crypto/chacha20poly1305/chacha20poly1305.go" ,
@@ -103,14 +134,25 @@ func TestHandler(t *testing.T) {
103
134
"go/src/archive/zip/a.go" : {Primary : []Owner {joetsai }, Secondary : []Owner {bradfitz }},
104
135
"crypto/chacha20poly1305/chacha20poly1305.go" : {Primary : []Owner {filippo , roland , securityTeam }},
105
136
},
137
+ archOses ,
138
+ },
139
+ {
140
+ "POST" , http .StatusOK , true ,
141
+ []string {},
142
+ copyEntries (entries ),
143
+ archOses ,
106
144
},
107
145
}
108
146
109
147
for _ , tc := range testCases {
110
148
var buf bytes.Buffer
111
149
if tc .paths != nil {
112
150
var oReq Request
151
+ oReq .Payload .All = tc .all
113
152
oReq .Payload .Paths = tc .paths
153
+ if len (tc .platforms ) > 0 {
154
+ oReq .Payload .Platform = true
155
+ }
114
156
if err := json .NewEncoder (& buf ).Encode (oReq ); err != nil {
115
157
t .Errorf ("could not encode request: %v" , err )
116
158
continue
@@ -146,6 +188,9 @@ func TestHandler(t *testing.T) {
146
188
if diff := cmp .Diff (oResp .Payload .Entries , tc .entries ); diff != "" {
147
189
t .Errorf ("%s: (-got +want)\n %s" , tc .method , diff )
148
190
}
191
+ if diff := cmp .Diff (oResp .Payload .Platforms , tc .platforms ); diff != "" {
192
+ t .Errorf ("%s: (-got +want)\n %s" , tc .method , diff )
193
+ }
149
194
}
150
195
}
151
196
0 commit comments