예제 #1
0
func TestSetMetadataMissingKey(t *testing.T) {
	RegisterTestingT(t)

	server, dbClient := testTools(200, `{'message': 'here'}`)
	defer server.Close()
	defer dbClient.RequestCache.DeleteData()
	m := adminApi.getBoneRouter(dbClient)

	// preparing to set mode through rest api
	var reqBody v1.SetMetadata
	// missing key
	reqBody.Value = "some_val"

	reqBodyBytes, err := json.Marshal(&reqBody)
	Expect(err).To(BeNil())

	// deleting through handler
	req, err := http.NewRequest("PUT", "/api/metadata", ioutil.NopCloser(bytes.NewBuffer(reqBodyBytes)))
	Expect(err).To(BeNil())

	//The response recorder used to record HTTP responses
	rec := httptest.NewRecorder()

	m.ServeHTTP(rec, req)
	Expect(rec.Code).To(Equal(http.StatusBadRequest))

	// checking response body
	body, err := ioutil.ReadAll(rec.Body)
	mr := v1.MessageResponse{}
	err = json.Unmarshal(body, &mr)

	Expect(mr.Message).To(Equal("Key not provided."))
}
예제 #2
0
func TestSetMetadata(t *testing.T) {
	RegisterTestingT(t)

	server, dbClient := testTools(200, `{'message': 'here'}`)
	defer server.Close()
	defer dbClient.RequestCache.DeleteData()
	m := adminApi.getBoneRouter(dbClient)

	// preparing to set mode through rest api
	var reqBody v1.SetMetadata
	reqBody.Key = "some_key"
	reqBody.Value = "some_val"

	reqBodyBytes, err := json.Marshal(&reqBody)
	Expect(err).To(BeNil())

	// deleting through handler
	req, err := http.NewRequest("PUT", "/api/metadata", ioutil.NopCloser(bytes.NewBuffer(reqBodyBytes)))
	Expect(err).To(BeNil())

	//The response recorder used to record HTTP responses
	rec := httptest.NewRecorder()

	m.ServeHTTP(rec, req)
	Expect(rec.Code).To(Equal(http.StatusCreated))

	// checking mode
	metaValue, err := dbClient.MetadataCache.Get([]byte("some_key"))
	Expect(err).To(BeNil())
	Expect(string(metaValue)).To(Equal("some_val"))
}