示例#1
0
文件: conn_test.go 项目: wbond/epp
func testLogin(t *testing.T) *Conn {
	c, err := NewConn(testDial(t))
	st.Assert(t, err, nil)
	err = c.Login(user, password, "")
	st.Assert(t, err, nil)
	return c
}
示例#2
0
文件: session_test.go 项目: wbond/epp
func TestConnLogout(t *testing.T) {
	c, err := NewConn(testDial(t))
	st.Assert(t, err, nil)
	err = c.Login(user, password, "")
	st.Assert(t, err, nil)
	err = c.Logout()
	st.Assert(t, err, nil)
}
示例#3
0
func TestPIRRateLimitText(t *testing.T) {
	req, err := NewRequest("google.org")
	st.Assert(t, err, nil)
	res, err := DefaultClient.Fetch(req)
	st.Assert(t, err, nil)
	st.Expect(t, res.MediaType, "text/plain")
	st.Expect(t, res.Charset, "windows-1252")
	res.Body = []byte("WHOIS LIMIT EXCEEDED - SEE WWW.PIR.ORG/WHOIS FOR DETAILS\n")
	res.DetectContentType("")
	st.Expect(t, res.MediaType, "text/plain")
	st.Expect(t, res.Charset, "windows-1252")
	h := res.Header()
	st.Expect(t, h.Get("Content-Type"), "text/plain; charset=windows-1252")
}
示例#4
0
func TestExample(t *testing.T) {
	st.Expect(t, "a", "a")
	st.Reject(t, 42, int64(42))

	st.Assert(t, "t", "t")
	st.Refute(t, 99, int64(99))
}
示例#5
0
func TestHello(t *testing.T) {
	c, err := NewConn(testDial(t))
	st.Assert(t, err, nil)
	err = c.Hello()
	st.Expect(t, err, nil)
	st.Expect(t, c.Greeting.ServerName, "ISPAPI EPP Server") // FIXME: brittle external dependency
}
示例#6
0
func TestRouteMiddleware(t *testing.T) {
	s := newTestServer(t)
	_, res := s.request("GET", "/route_middleware")
	defer res.Body.Close()
	expectHeaders(t, res)
	body, _ := ioutil.ReadAll(res.Body)
	st.Assert(t, string(body), "middleware1 -> middleware2 -> Hello, world! -> middleware2 -> middleware1")
}
示例#7
0
func TestEcho(t *testing.T) {
	s := newTestServer(t)
	_, res := s.request("GET", "/api/echo/hip-hop")
	defer res.Body.Close()
	expectHeaders(t, res)
	body, _ := ioutil.ReadAll(res.Body)
	st.Assert(t, string(body), "hip-hop")
}
示例#8
0
文件: conn_test.go 项目: wbond/epp
func testDial(t *testing.T) net.Conn {
	if testing.Short() {
		t.Skip("network-dependent")
	}
	conn, err := tls.Dial("tcp", addr, nil)
	st.Assert(t, err, nil)
	return conn
}
示例#9
0
func TestItWorks(t *testing.T) {
	res, err := goreq.Request{
		Uri:     TargetHost,
		Timeout: 1 * time.Second,
	}.Do()
	defer func() {
		if res.Body != nil {
			res.Body.Close()
		}
	}()

	st.Assert(t, err, nil)
	st.Expect(t, res.StatusCode, http.StatusOK)

	body, err := res.Body.ToString()
	st.Assert(t, err, nil)
	st.Expect(t, strings.TrimSpace(body), "ok")
}
示例#10
0
func TestReadMIME(t *testing.T) {
	fns, err := whoistest.ResponseFiles()
	st.Assert(t, err, nil)
	for _, fn := range fns {
		// fmt.Printf("%s\n", fn)
		res, err := ReadMIMEFile(fn)
		st.Reject(t, res, nil)
		st.Expect(t, err, nil)
		// fmt.Printf("%#v\n\n", res)
	}
}
示例#11
0
// Prints failure output, including the correct line number and example index.
func TestFailedTableMessages(t *testing.T) {
	table := []struct{ val int }{
		{0}, {1}, {2},
	}
	// Continues if expectation fails
	for i, example := range table {
		st.Expect(t, example.val, 1, i)
	}
	// Stops when first assertion fails
	for _, example := range table {
		st.Assert(t, example.val, 1)
	}
}
示例#12
0
func TestItWorks(t *testing.T) {
	acceptanceTest(t)

	res, err := goreq.Request{
		Uri:     "http://" + ApplicationHost, // HL
		Timeout: 1 * time.Second,
	}.Do()
	defer func() {
		if res.Body != nil {
			res.Body.Close()
		}
	}()

	st.Assert(t, err, nil)
	st.Expect(t, res.StatusCode, http.StatusOK)
}
示例#13
0
func TestTableExample(t *testing.T) {
	examples := []struct{ a, t string }{
		{"first", "first"},
		{"second", "second"},
	}

	// Pass example index to improve the error message for table-based tests.
	for i, ex := range examples {
		st.Expect(t, ex, ex, i)
		st.Reject(t, ex, &ex, i)
	}

	// Cannot pass index into Assert or Refute, they fail fast.
	for _, ex := range examples {
		st.Assert(t, ex, ex)
		st.Refute(t, ex, &ex)
	}
}
示例#14
0
// Prints failure output, including the correct line number.
func TestFailedAssertMessage(t *testing.T) {
	type chicken struct{}
	type egg struct{}
	st.Assert(t, egg{}, chicken{})
}