コード例 #1
0
ファイル: server_test.go プロジェクト: ZhuZhengyi/eris-db
func TestIdFull(t *testing.T) {
	idPool := NewIdPool(10)
	for i := 0; i < 10; i++ {
		idPool.GetId()
	}
	_, err := idPool.GetId()
	assert.Error(t, err)
}
コード例 #2
0
ファイル: binding_test.go プロジェクト: ZhuZhengyi/eris-db
func testBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
	assert.Equal(t, b.Name(), name)

	obj := FooStruct{}
	req := requestWithBody("POST", path, body)
	err := b.Bind(req, &obj)
	assert.NoError(t, err)
	assert.Equal(t, obj.Foo, "bar")

	obj = FooStruct{}
	req = requestWithBody("POST", badPath, badBody)
	err = JSON.Bind(req, &obj)
	assert.Error(t, err)
}
コード例 #3
0
ファイル: context_test.go プロジェクト: ZhuZhengyi/eris-db
func TestContextBadAutoBind(t *testing.T) {
	c, w, _ := createTestContext()
	c.Request, _ = http.NewRequest("POST", "http://example.com", bytes.NewBufferString("\"foo\":\"bar\", \"bar\":\"foo\"}"))
	c.Request.Header.Add("Content-Type", MIMEJSON)
	var obj struct {
		Foo string `json:"foo"`
		Bar string `json:"bar"`
	}

	assert.False(t, c.IsAborted())
	assert.Error(t, c.Bind(&obj))
	c.Writer.WriteHeaderNow()

	assert.Empty(t, obj.Bar)
	assert.Empty(t, obj.Foo)
	assert.Equal(t, w.Code, 400)
	assert.True(t, c.IsAborted())
}
コード例 #4
0
ファイル: binding_test.go プロジェクト: ZhuZhengyi/eris-db
func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) {
	b := Form
	assert.Equal(t, b.Name(), "form")

	obj := FooBarStruct{}
	req := requestWithBody(method, path, body)
	if method == "POST" {
		req.Header.Add("Content-Type", MIMEPOSTForm)
	}
	err := b.Bind(req, &obj)
	assert.NoError(t, err)
	assert.Equal(t, obj.Foo, "bar")
	assert.Equal(t, obj.Bar, "foo")

	obj = FooBarStruct{}
	req = requestWithBody(method, badPath, badBody)
	err = JSON.Bind(req, &obj)
	assert.Error(t, err)
}
コード例 #5
0
func TestRun(t *testing.T) {
	buffer := new(bytes.Buffer)
	router := New()
	go func() {
		router.Use(LoggerWithWriter(buffer))
		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
		router.Run(":5150")
	}()
	// have to wait for the goroutine to start and run the server
	// otherwise the main thread will complete
	time.Sleep(5 * time.Millisecond)

	assert.Error(t, router.Run(":5150"))

	resp, err := http.Get("http://localhost:5150/example")
	defer resp.Body.Close()
	assert.NoError(t, err)

	body, ioerr := ioutil.ReadAll(resp.Body)
	assert.NoError(t, ioerr)
	assert.Equal(t, "it worked", string(body[:]), "resp body should match")
	assert.Equal(t, "200 OK", resp.Status, "should get a 200")
}
コード例 #6
0
ファイル: requirements.go プロジェクト: alexandrev/eris-db
// Error asserts that a function returned an error (i.e. not `nil`).
//
//   actualObj, err := SomeFunction()
//   require.Error(t, err, "An error was expected")
//   require.Equal(t, err, expectedError)
//   }
func Error(t TestingT, err error, msgAndArgs ...interface{}) {
	if !assert.Error(t, err, msgAndArgs...) {
		t.FailNow()
	}
}
コード例 #7
0
ファイル: middleware_test.go プロジェクト: ZhuZhengyi/eris-db
// Test no colon separated filter and proper filters mixed.
func TestQueryNoColonSeparatorMulti(t *testing.T) {
	_, err := _parseSearchQuery("test test1:24 test2")
	assert.Error(t, err, "Should detect missing colon.")
}
コード例 #8
0
ファイル: middleware_test.go プロジェクト: ZhuZhengyi/eris-db
// Test a range query with no lower bounds term.
func TestRangeQueryBotchedMin(t *testing.T) {
	_, err := _parseSearchQuery("test:..5")
	assert.Error(t, err, "Malformed range-query passed")
}
コード例 #9
0
ファイル: binding_test.go プロジェクト: ZhuZhengyi/eris-db
func TestValidationFails(t *testing.T) {
	var obj FooStruct
	req := requestWithBody("POST", "/", `{"bar": "foo"}`)
	err := JSON.Bind(req, &obj)
	assert.Error(t, err)
}
コード例 #10
0
func TestBadUnixSocket(t *testing.T) {
	router := New()
	assert.Error(t, router.RunUnix("#/tmp/unix_unit_test"))
}
コード例 #11
0
// Test no colon separated filter.
func TestQueryNoColonSeparator(t *testing.T) {
	_, err := _parseQuery("test")
	assert.Error(t, err, "Should detect missing colon.")
}
コード例 #12
0
// Test a range query with no upper bounds term.
func TestRangeQueryBotchedMax(t *testing.T) {
	_, err := _parseQuery("test:5..")
	assert.Error(t, err, "Malformed range-query passed")
}