Exemple #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())
}
Exemple #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())
}
Exemple #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())
}
Exemple #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)
}
Exemple #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())
}
Exemple #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())
}
Exemple #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")

}
Exemple #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())
}
Exemple #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())
}
Exemple #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())
}
Exemple #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`))
}
Exemple #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"))
}
Exemple #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"))
}
Exemple #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"))
}
Exemple #15
0
func testFunc(t *testing.T) {
	r := runner.New(t, *url)
	fmt.Println("silk: running", len(paths), "file(s)...")
	r.RunGlob(paths, nil)
}
Exemple #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"))
}