MCPcopy
hub / github.com/perkeep/perkeep / test

Method test

pkg/search/handler_test.go:875–937  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

873}
874
875func (ht handlerTest) test(t *testing.T) {
876 SetTestHookBug121(func() {})
877
878 ixo := ht.setup(t)
879 idx := ixo.index
880 h := NewHandler(idx, owner)
881
882 var body io.Reader
883 var method = "GET"
884 if ht.postBody != "" {
885 method = "POST"
886 body = strings.NewReader(ht.postBody)
887 }
888 req, err := http.NewRequest(method, "/camli/search/"+ht.query, body)
889 if err != nil {
890 t.Fatalf("%s: bad query: %v", ht.name, err)
891 }
892 req.Header.Set(httputil.PathSuffixHeader, req.URL.Path[1:])
893
894 rr := httptest.NewRecorder()
895 rr.Body = new(bytes.Buffer)
896
897 h.ServeHTTP(rr, req)
898 got := rr.Body.Bytes()
899
900 if len(ht.wantDescribed) > 0 {
901 dr := new(DescribeResponse)
902 if err := json.NewDecoder(bytes.NewReader(got)).Decode(dr); err != nil {
903 t.Fatalf("On test %s: Non-JSON response: %s", ht.name, got)
904 }
905 var gotDesc []string
906 for k := range dr.Meta {
907 gotDesc = append(gotDesc, k)
908 }
909 sort.Strings(ht.wantDescribed)
910 sort.Strings(gotDesc)
911 if !reflect.DeepEqual(gotDesc, ht.wantDescribed) {
912 t.Errorf("On test %s: described blobs:\n%v\nwant:\n%v\n",
913 ht.name, gotDesc, ht.wantDescribed)
914 }
915 if ht.want == nil {
916 return
917 }
918 }
919
920 want, _ := json.MarshalIndent(ht.want, "", " ")
921 trim := bytes.TrimSpace
922
923 if bytes.Equal(trim(got), trim(want)) {
924 return
925 }
926
927 // Try with re-encoded got, since the JSON ordering doesn't matter
928 // to the test,
929 gotj := parseJSON(string(got))
930 got2, _ := json.MarshalIndent(gotj, "", " ")
931 if bytes.Equal(got2, want) {
932 return

Callers 15

TestSearchDescribeFunction · 0.45
TestHandlerFunction · 0.45
SizzleFunction · 0.45
jquery.jsFile · 0.45
winnowFunction · 0.45
dataAttrFunction · 0.45
buildFragmentFunction · 0.45
fixInputFunction · 0.45
domManipFunction · 0.45
curCSSFunction · 0.45
getWidthOrHeightFunction · 0.45
ajaxHandleResponsesFunction · 0.45

Calls 10

ServeHTTPMethod · 0.95
DiffFunction · 0.92
SetTestHookBug121Function · 0.85
setupMethod · 0.80
NewRequestMethod · 0.80
EqualMethod · 0.80
NewHandlerFunction · 0.70
parseJSONFunction · 0.70
FatalfMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected