Esempio n. 1
0
func TestValidCode(t *testing.T) {
	s, err := DefaultDoc.GetStatusCode("200")

	assert.Nil(t, err)
	assert.Equal(t, s.Code, "200")
	assert.Equal(t, s.Text, "OK")
}
Esempio n. 2
0
func TestDocRecognizeHeader(t *testing.T) {
	s, err := DefaultDoc.GetResourceFor("te")

	require.Nil(t, err)

	switch s.(type) {
	case Header:
		// success
	default:
		t.Fatal("GetResourceFor(\"te\") should return a Header")
	}

	assert.Equal(t, "TE", s.(Header).Text)
}
Esempio n. 3
0
func TestDocRecognizeMethod(t *testing.T) {
	s, err := DefaultDoc.GetResourceFor("options")

	require.Nil(t, err)

	switch s.(type) {
	case Method:
		// success
	default:
		t.Fatal("GetResourceFor(\"options\") should return a Method")
	}

	assert.Equal(t, "OPTIONS", s.(Method).Verb)
}
Esempio n. 4
0
func TestDocRecognizeStatus(t *testing.T) {
	s, err := DefaultDoc.GetResourceFor("304")

	require.Nil(t, err)

	switch s.(type) {
	case StatusCode:
		// success
	default:
		t.Fatal("GetResourceFor(\"304\") should return a StatusCode")
	}

	assert.Equal(t, "304", s.(StatusCode).Code)
}
Esempio n. 5
0
func TestDocRecognizeAllMethods(t *testing.T) {
	check := func(name, expected string) {
		s, err := DefaultDoc.GetResourceFor(name)
		require.Nil(t, err,
			fmt.Sprintf("GetResourceFor(%s) shouldn't return an error", name))
		assert.Equal(t, expected, s.(Method).Verb,
			fmt.Sprintf("GetResourceFor(%s) should return %s", name, expected))
	}

	check("connect", "CONNECT")
	check("delete", "DELETE")
	check("get", "GET")
	check("head", "HEAD")
	check("options", "OPTIONS")
	check("patch", "PATCH")
	check("post", "POST")
	check("put", "PUT")
	check("trace", "TRACE")
}
Esempio n. 6
0
func TestInValidCode(t *testing.T) {
	_, err := DefaultDoc.GetStatusCode("123")

	assert.Equal(t, err, ErrUnknownStatusCode)
}
Esempio n. 7
0
// Equal asserts that two objects are equal.
//
//    require.Equal(t, 123, 123, "123 and 123 should be equal")
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) {
	if !assert.Equal(t, expected, actual, msgAndArgs...) {
		t.FailNow()
	}
}