@@ -23,6 +23,7 @@ import (
2323 "net/http"
2424 "net/http/httptest"
2525 "reflect"
26+ "strconv"
2627 "testing"
2728
2829 "github.com/google/go-cmp/cmp"
@@ -54,6 +55,8 @@ func TestNetAPI(t *testing.T) {
5455 var gotReqHashPrefix , wantReqHashPrefix []byte
5556 var gotReqThreatTypes , wantReqThreatTypes []pb.ThreatType
5657 var gotResp , wantResp proto.Message
58+ var gotMaxDiffEntries , wantMaxDiffEntries []int32
59+ var gotMaxDatabaseEntries , wantMaxDatabaseEntries []int32
5760 responseMisformatter := ""
5861 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
5962 var p []byte
@@ -88,15 +91,33 @@ func TestNetAPI(t *testing.T) {
8891 gotReqThreatTypes = append (gotReqThreatTypes ,
8992 pb .ThreatType (pb .ThreatType_value [threat ]))
9093 }
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 ))
91112 } 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 )
93114 }
94115 }
95116 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 )
97118 }
98119 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 )
100121 }
101122 }))
102123 defer ts .Close ()
@@ -109,6 +130,8 @@ func TestNetAPI(t *testing.T) {
109130 // Test that ListUpdate marshal/unmarshal works.
110131 wantReqThreatType = pb .ThreatType_MALWARE
111132 wantReqCompressionTypes = []pb.CompressionType {0 , 1 , 2 }
133+ wantMaxDiffEntries = []int32 {1024 }
134+ wantMaxDatabaseEntries = []int32 {1024 }
112135
113136 wantResp = & pb.ComputeThreatListDiffResponse {
114137 ResponseType : 1 ,
@@ -121,6 +144,8 @@ func TestNetAPI(t *testing.T) {
121144 ThreatType : wantReqThreatType ,
122145 Constraints : & pb.ComputeThreatListDiffRequest_Constraints {
123146 SupportedCompressions : wantReqCompressionTypes ,
147+ MaxDiffEntries : 1024 ,
148+ MaxDatabaseEntries : 1024 ,
124149 },
125150 VersionToken : []byte {},
126151 }
@@ -140,6 +165,14 @@ func TestNetAPI(t *testing.T) {
140165 if ! proto .Equal (gotResp , wantResp ) {
141166 t .Errorf ("mismatching ListUpdate responses:\n got %+v\n want %+v" , gotResp , wantResp )
142167 }
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+ }
143176
144177 // Test that HashLookup marshal/unmarshal works.
145178 wantReqHashPrefix = []byte ("aaaa" )
0 commit comments