Exemplo n.º 1
0
func TestSuggestionJSON(t *testing.T) {
	client, server := test.Client(exampleResponseJSON)
	defer server.Close()
	want :=
		SuggestionsResponse{
			Suggestions: []string{"data", "database"},
		}
	// Using Basic Auth for test so initial call isn't actually made
	respHandle := SuggestionsResponseHandle{Format: handle.JSON}
	query :=
		Query{
			Queries: []interface{}{
				TermQuery{Terms: []string{"data"}},
			},
		}
	qh := QueryHandle{}
	qh.Serialize(query)
	err := StructuredSuggestions(client, &qh, "data", 10, "all", &respHandle)
	resp := respHandle.Get()
	if err != nil {
		t.Errorf("Error = %v", err)
	} else if resp == nil {
		t.Errorf("No response found")
	} else if !reflect.DeepEqual(*resp, want) {
		t.Errorf("Search Response = %+v, Want = %+v", spew.Sdump(*resp), spew.Sdump(want))
	}
}
Exemplo n.º 2
0
func TestDeleteExtensions(t *testing.T) {
	want := testHelper.NormalizeSpace(``)
	client, _ := test.Client(want)
	err := deleteExtensions(client, "/")
	if err != nil {
		t.Errorf("Error encountered: %v", err)
	}
}
Exemplo n.º 3
0
func TestExecute(t *testing.T) {
	want := `{"success":true}`
	client, _ := test.Client(want)
	req, err := http.NewRequest("GET", client.Base(), nil)
	respHandle := handle.RawHandle{Format: handle.JSON}
	Execute(client, req, &respHandle)
	result := testHelper.NormalizeSpace(respHandle.Serialized())
	if err != nil {
		t.Errorf("Error = %v", err)
	} else if want != result {
		t.Errorf("Result = %v, want %v", spew.Sdump(result), spew.Sdump(want))
	}
}
Exemplo n.º 4
0
func TestCreateExtension(t *testing.T) {
	want := testHelper.NormalizeSpace(`{
  "resources": {
    "resource": [
      {
        "name": "example",
        "title": "",
        "version": "",
        "provider-name": "Acme Widgets",
        "description": "",
        "methods": {
          "method": [
            {
              "parameter": [
                {
                  "parameter-name": "the-uri",
                  "parameter-type": "string"
                }
              ],
              "method-name": "get"
            }
          ]
        },
        "resource-source": "/v1/resources/example"
      }
    ]
  }
}`)
	client, _ := test.Client(want)
	responseHandle := handle.MapHandle{
		Format: handle.JSON,
	}
	err := listExtensions(client, "/", &responseHandle)
	result := testHelper.NormalizeSpace(responseHandle.Serialized())
	if err != nil {
		t.Errorf("Error encountered: %v", err)
	} else if want != result {
		t.Errorf("Result = %v, want = %v", result, want)
	}
}