Пример #1
0
func TestRunFileSuccessNoBody(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	r.RunFile("../testfiles/success/echo.nobody.success.silk.md")
	is.False(subT.Failed())
}
Пример #2
0
// https://github.com/matryer/silk/issues/31
func TestIssue31(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	r.RunFile("../testfiles/success/issue-31.silk.md")
	is.False(subT.Failed())
}
Пример #3
0
// https://github.com/matryer/silk/issues/37
func TestStandardSeparator(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	os.Setenv("$AppNameFromEnv", "Silk")
	r := runner.New(subT, s.URL)
	r.RunFile("../testfiles/success/issue-37.silk.md")
	is.False(subT.Failed())
}
Пример #4
0
func TestGlob(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	r.Log = func(s string) {} // don't bother logging
	r.RunGlob(filepath.Glob("../testfiles/failure/echo.*.silk.md"))
	is.True(subT.Failed())
}
Пример #5
0
func TestRunGroupSuccess(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	g, err := parse.ParseFile("../testfiles/success/echo.success.silk.md")
	is.NoErr(err)
	r.RunGroup(g...)
	is.False(subT.Failed())
}
Пример #6
0
func TestFailureFieldsDifferentTypes(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	var logs []string
	r.Log = func(s string) {
		logs = append(logs, s)
	}
	g, err := parse.ParseFile("../testfiles/failure/echo.failure.fieldsdifferenttypes.silk.md")
	is.NoErr(err)
	r.RunGroup(g...)
	is.True(subT.Failed())
	logstr := strings.Join(logs, "\n")

	is.True(strings.Contains(logstr, `Status expected string: "400"  actual float64: 200`))
}
Пример #7
0
func TestFailureWrongHeader(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	var logs []string
	r.Log = func(s string) {
		logs = append(logs, s)
	}
	g, err := parse.ParseFile("../testfiles/failure/echo.failure.wrongheader.silk.md")
	is.NoErr(err)
	r.RunGroup(g...)
	is.True(subT.Failed())
	logstr := strings.Join(logs, "\n")
	is.True(strings.Contains(logstr, `Content-Type expected string: "wrong/type"  actual string: "text/plain; charset=utf-8"`))
	is.True(strings.Contains(logstr, "--- FAIL: GET /echo"))
	is.True(strings.Contains(logstr, "../testfiles/failure/echo.failure.wrongheader.silk.md:22 - Content-Type doesn't match"))
}
Пример #8
0
func TestFailureWrongBody(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	var logs []string
	r.Log = func(s string) {
		logs = append(logs, s)
	}
	g, err := parse.ParseFile("../testfiles/failure/echo.failure.wrongbody.silk.md")
	is.NoErr(err)
	r.RunGroup(g...)
	is.True(subT.Failed())
	logstr := strings.Join(logs, "\n")
	is.True(strings.Contains(logstr, "body expected:"))
	is.True(strings.Contains(logstr, "GET /echo"))
	is.True(strings.Contains(logstr, "Hello silky."))
	is.True(strings.Contains(logstr, "actual:"))
	is.True(strings.Contains(logstr, "GET /echo"))
	is.True(strings.Contains(logstr, "Hello silk."))
	is.True(strings.Contains(logstr, "--- FAIL: GET /echo"))
	is.True(strings.Contains(logstr, "../testfiles/failure/echo.failure.wrongbody.silk.md:14 - body doesn't match"))
}