@@ -23,6 +23,7 @@ import (
23
23
"net/http"
24
24
"net/http/httptest"
25
25
"reflect"
26
+ "strconv"
26
27
"testing"
27
28
28
29
"github.com/google/go-cmp/cmp"
@@ -54,6 +55,8 @@ func TestNetAPI(t *testing.T) {
54
55
var gotReqHashPrefix , wantReqHashPrefix []byte
55
56
var gotReqThreatTypes , wantReqThreatTypes []pb.ThreatType
56
57
var gotResp , wantResp proto.Message
58
+ var gotMaxDiffEntries , wantMaxDiffEntries []int32
59
+ var gotMaxDatabaseEntries , wantMaxDatabaseEntries []int32
57
60
responseMisformatter := ""
58
61
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
59
62
var p []byte
@@ -88,15 +91,33 @@ func TestNetAPI(t *testing.T) {
88
91
gotReqThreatTypes = append (gotReqThreatTypes ,
89
92
pb .ThreatType (pb .ThreatType_value [threat ]))
90
93
}
94
+ } else if key == maxDiffEntriesKey {
95
+ if len (value ) == 0 {
96
+ t .Fatalf ("Missing value for key %v" , key )
97
+ }
98
+ i , err := strconv .ParseInt (value [0 ], 10 , 32 )
99
+ if err != nil {
100
+ t .Fatalf ("Error parsing %q: %v" , value [0 ], err )
101
+ }
102
+ gotMaxDiffEntries = append (gotMaxDiffEntries , int32 (i ))
103
+ } else if key == maxDatabaseEntriesKey {
104
+ if len (value ) == 0 {
105
+ t .Fatalf ("Missing value for key %v" , key )
106
+ }
107
+ i , err := strconv .ParseInt (value [0 ], 10 , 32 )
108
+ if err != nil {
109
+ t .Fatalf ("Error parsing %q: %v" , value [0 ], err )
110
+ }
111
+ gotMaxDatabaseEntries = append (gotMaxDatabaseEntries , int32 (i ))
91
112
} else if key != "key" {
92
- t .Fatalf ("unexpected request param error for key: %v" , key )
113
+ t .Fatalf ("Unexpected request param error for key: %v" , key )
93
114
}
94
115
}
95
116
if p , err = protojson .Marshal (wantResp ); err != nil {
96
- t .Fatalf ("unexpected json MarshalToString error: %v" , err )
117
+ t .Fatalf ("Unexpected json MarshalToString error: %v" , err )
97
118
}
98
119
if _ , err := w .Write ([]byte (responseMisformatter + string (p ))); err != nil {
99
- t .Fatalf ("unexpected ResponseWriter.Write error: %v" , err )
120
+ t .Fatalf ("Unexpected ResponseWriter.Write error: %v" , err )
100
121
}
101
122
}))
102
123
defer ts .Close ()
@@ -109,6 +130,8 @@ func TestNetAPI(t *testing.T) {
109
130
// Test that ListUpdate marshal/unmarshal works.
110
131
wantReqThreatType = pb .ThreatType_MALWARE
111
132
wantReqCompressionTypes = []pb.CompressionType {0 , 1 , 2 }
133
+ wantMaxDiffEntries = []int32 {1024 }
134
+ wantMaxDatabaseEntries = []int32 {1024 }
112
135
113
136
wantResp = & pb.ComputeThreatListDiffResponse {
114
137
ResponseType : 1 ,
@@ -121,6 +144,8 @@ func TestNetAPI(t *testing.T) {
121
144
ThreatType : wantReqThreatType ,
122
145
Constraints : & pb.ComputeThreatListDiffRequest_Constraints {
123
146
SupportedCompressions : wantReqCompressionTypes ,
147
+ MaxDiffEntries : 1024 ,
148
+ MaxDatabaseEntries : 1024 ,
124
149
},
125
150
VersionToken : []byte {},
126
151
}
@@ -140,6 +165,14 @@ func TestNetAPI(t *testing.T) {
140
165
if ! proto .Equal (gotResp , wantResp ) {
141
166
t .Errorf ("mismatching ListUpdate responses:\n got %+v\n want %+v" , gotResp , wantResp )
142
167
}
168
+ if ! reflect .DeepEqual (gotMaxDiffEntries , wantMaxDiffEntries ) {
169
+ t .Errorf ("mismatching ListUpdate max diff entries:\n got %+v\n want %+v" ,
170
+ gotMaxDiffEntries , wantMaxDiffEntries )
171
+ }
172
+ if ! reflect .DeepEqual (gotMaxDatabaseEntries , wantMaxDatabaseEntries ) {
173
+ t .Errorf ("mismatching ListUpdate max database entries:\n got %+v\n want %+v" ,
174
+ gotMaxDatabaseEntries , wantMaxDatabaseEntries )
175
+ }
143
176
144
177
// Test that HashLookup marshal/unmarshal works.
145
178
wantReqHashPrefix = []byte ("aaaa" )
0 commit comments