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 }
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) }
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") }
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)) }
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 }
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") }
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") }
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 }
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") }
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) } }
// 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) } }
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) }
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) } }
// Prints failure output, including the correct line number. func TestFailedAssertMessage(t *testing.T) { type chicken struct{} type egg struct{} st.Assert(t, egg{}, chicken{}) }