@@ -19,6 +19,7 @@ import (
19
19
"context"
20
20
"encoding/hex"
21
21
"encoding/json"
22
+ "fmt"
22
23
"io"
23
24
"io/ioutil"
24
25
gohttp "net/http"
@@ -109,8 +110,8 @@ func TestHandler_Endpoints(t *testing.T) {
109
110
t .Fatalf ("unexpected status code: %d" , w .Code )
110
111
}
111
112
body := w .Body .String ()
112
- target := `{"indexes":[{"name":"i0","options":{"keys":false,"trackExistence":false},"fields":[{"name":"f0","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}},{"name":"f1","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":1048576 },{"name":"i1","options":{"keys":false,"trackExistence":false},"fields":[{"name":"f0","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":1048576 }]}
113
- `
113
+ target := fmt . Sprintf ( `{"indexes":[{"name":"i0","options":{"keys":false,"trackExistence":false},"fields":[{"name":"f0","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}},{"name":"f1","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":%d },{"name":"i1","options":{"keys":false,"trackExistence":false},"fields":[{"name":"f0","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":%[1]d }]}
114
+ ` , pilosa . ShardWidth )
114
115
if body != target {
115
116
t .Fatalf ("%s != %s" , target , body )
116
117
}
@@ -298,7 +299,7 @@ func TestHandler_Endpoints(t *testing.T) {
298
299
h .ServeHTTP (w , test .MustNewHTTPRequest ("POST" , "/index/i0/query" , strings .NewReader ("Row(f0=30)" )))
299
300
if w .Code != gohttp .StatusOK {
300
301
t .Fatalf ("unexpected status code: %d" , w .Code )
301
- } else if body := w .Body .String (); body != `{"results":[{"attrs":{},"columns":[1048577,1048578,3145732 ]}]}` + "\n " {
302
+ } else if body := w .Body .String (); body != fmt . Sprintf ( `{"results":[{"attrs":{},"columns":[%d,%d,%d ]}]}` , pilosa . ShardWidth + 1 , pilosa . ShardWidth + 2 , 3 * pilosa . ShardWidth + 4 ) + "\n " {
302
303
t .Fatalf ("unexpected body: %s" , body )
303
304
}
304
305
})
@@ -315,10 +316,11 @@ func TestHandler_Endpoints(t *testing.T) {
315
316
t .Run ("ColumnAttrs_JSON" , func (t * testing.T ) {
316
317
w := httptest .NewRecorder ()
317
318
h .ServeHTTP (w , test .MustNewHTTPRequest ("POST" , "/index/i0/query?columnAttrs=true" , strings .NewReader ("Row(f0=30)" )))
319
+ exp := fmt .Sprintf (`{"results":[{"attrs":{"a":"b","c":1,"d":true},"columns":[%[1]d,%[2]d,%[3]d]}],"columnAttrs":[{"id":%[1]d,"attrs":{"x":"y"}},{"id":%[2]d,"attrs":{"y":123,"z":false}}]}` , pilosa .ShardWidth + 1 , pilosa .ShardWidth + 2 , 3 * pilosa .ShardWidth + 4 ) + "\n "
318
320
if w .Code != gohttp .StatusOK {
319
321
t .Fatalf ("unexpected status code: %d. body: %s" , w .Code , w .Body .String ())
320
- } else if body := w .Body .String (); body != `{"results":[{"attrs":{"a":"b","c":1,"d":true},"columns":[1048577,1048578,3145732]}],"columnAttrs":[{"id":1048577,"attrs":{"x":"y"}},{"id":1048578,"attrs":{"y":123,"z":false}}]}` + " \n " {
321
- t .Fatalf ("unexpected body: %s " , body )
322
+ } else if body := w .Body .String (); body != exp {
323
+ t .Fatalf ("unexpected body: \n %s \n got: \n %s " , body , exp )
322
324
}
323
325
})
324
326
0 commit comments