Example #1
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())
}
Example #2
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())
}
Example #3
0
func TestBodyField(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoDataHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	r.RunFile("../testfiles/success/body-as-field.silk.md")
	is.False(subT.Failed())
}
Example #4
0
func testFunc(t *testing.T) {
	r := runner.New(t, *url)
	files, err := filepath.Glob(root)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("running", len(files), "file(s)")
	r.RunGlob(files, nil)
}
Example #5
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())
}
Example #6
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())
}
Example #7
0
func TestHello(t *testing.T) {

	// start test server
	server := httptest.NewServer(example.NewServer())
	defer server.Close()

	// make a new runner using the server URL as the target
	// and run the test file.
	runner.New(t, server.URL).RunFile("hello.silk.md")

}
Example #8
0
// https://github.com/matryer/silk/issues/2
func TestCapturedVars(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoDataHandler())
	defer s.Close()
	os.Setenv("$EnvStatus", "awesome")
	os.Setenv("$AppNameFromEnv", "Silk")
	r := runner.New(subT, s.URL)
	r.RunFile("../testfiles/success/captured-vars.silk.md")
	is.False(subT.Failed())
}
Example #9
0
func TestRunJsonModesFailure(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoRawHandler())
	defer s.Close()
	r := runner.New(subT, s.URL)
	g, err := parse.ParseFile("../testfiles/failure/echoraw.failure.jsonmodes.silk.md")
	is.NoErr(err)
	r.RunGroup(g...)
	is.True(subT.Failed())
}
Example #10
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())
}
Example #11
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`))
}
Example #12
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"))
}
Example #13
0
// https://github.com/matryer/silk/issues/28
func TestFailureNonTrimmedExpection(t *testing.T) {
	is := is.New(t)
	subT := &testT{}
	s := httptest.NewServer(testutil.EchoDataHandler())
	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.nontrimmedexpectation.silk.md")
	is.NoErr(err)
	r.RunGroup(g...)
	is.True(subT.Failed())
	logstr := strings.Join(logs, "\n")

	is.True(strings.Contains(logstr, `Data.body.status expected: "awesome"  actual: " awesome"`))
	is.True(strings.Contains(logstr, "--- FAIL: GET /echo"))
	is.True(strings.Contains(logstr, "../testfiles/failure/echo.failure.nontrimmedexpectation.silk.md:18 - Data.body.status doesn't match"))
}
Example #14
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"))
}
Example #15
0
File: main.go Project: matryer/silk
func testFunc(t *testing.T) {
	r := runner.New(t, *url)
	fmt.Println("silk: running", len(paths), "file(s)...")
	r.RunGlob(paths, nil)
}
Example #16
0
func (q *QualityReportSuite) TestAPI(c *C) {
	s := httptest.NewServer(q.Engine)
	defer s.Close()
	runner.New(c, s.URL).RunGlob(filepath.Glob("../api_doc/*.silk.md"))
}