From 8ebb3634fb9fbaacec2b65a5bbae16ad74b89ed7 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 16 Apr 2022 00:36:38 +0800 Subject: [PATCH] fix: unittest with failfast --- hrp/internal/boomer/runner_test.go | 2 +- hrp/internal/boomer/stats_test.go | 2 +- hrp/internal/builtin/assertion_test.go | 20 ++--- hrp/internal/builtin/utils.go | 3 +- hrp/internal/har2case/core_test.go | 94 ++++++++++----------- hrp/internal/scaffold/examples_test.go | 6 +- hrp/internal/scaffold/templates/pytest.ini | 6 ++ hrp/internal/sdk/client_test.go | 2 +- hrp/parser.go | 2 +- hrp/parser_test.go | 96 +++++++++++----------- hrp/plugin_test.go | 14 ++-- hrp/response_test.go | 8 +- hrp/runner_test.go | 24 +++--- hrp/testcase_test.go | 22 ++--- 14 files changed, 154 insertions(+), 147 deletions(-) create mode 100644 hrp/internal/scaffold/templates/pytest.ini diff --git a/hrp/internal/boomer/runner_test.go b/hrp/internal/boomer/runner_test.go index a4f674b4..549980c9 100644 --- a/hrp/internal/boomer/runner_test.go +++ b/hrp/internal/boomer/runner_test.go @@ -109,6 +109,6 @@ func TestLoopCount(t *testing.T) { go runner.start() <-runner.stopChan if !assert.Equal(t, runner.loop.loopCount, atomic.LoadInt64(&runner.loop.finishedCount)) { - t.Fail() + t.Fatal() } } diff --git a/hrp/internal/boomer/stats_test.go b/hrp/internal/boomer/stats_test.go index afe0b41e..1d4806a2 100644 --- a/hrp/internal/boomer/stats_test.go +++ b/hrp/internal/boomer/stats_test.go @@ -155,7 +155,7 @@ func TestSerializeStats(t *testing.T) { first := serialized[0] entry, err := deserializeStatsEntry(first) if err != nil { - t.Fail() + t.Fatal() } if entry.Name != "success" { diff --git a/hrp/internal/builtin/assertion_test.go b/hrp/internal/builtin/assertion_test.go index d919464e..aa7d4bde 100644 --- a/hrp/internal/builtin/assertion_test.go +++ b/hrp/internal/builtin/assertion_test.go @@ -20,7 +20,7 @@ func TestStartsWith(t *testing.T) { for _, data := range testData { if !assert.True(t, StartsWith(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -38,7 +38,7 @@ func TestEndsWith(t *testing.T) { for _, data := range testData { if !assert.True(t, EndsWith(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -58,7 +58,7 @@ func TestEqualLength(t *testing.T) { for _, data := range testData { if !assert.True(t, EqualLength(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -78,7 +78,7 @@ func TestLessThanLength(t *testing.T) { for _, data := range testData { if !assert.True(t, LessThanLength(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -98,7 +98,7 @@ func TestLessOrEqualsLength(t *testing.T) { for _, data := range testData { if !assert.True(t, LessOrEqualsLength(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -115,7 +115,7 @@ func TestGreaterThanLength(t *testing.T) { for _, data := range testData { if !assert.True(t, GreaterThanLength(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -135,7 +135,7 @@ func TestGreaterOrEqualsLength(t *testing.T) { for _, data := range testData { if !assert.True(t, GreaterOrEqualsLength(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -152,7 +152,7 @@ func TestContainedBy(t *testing.T) { for _, data := range testData { if !assert.True(t, ContainedBy(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -169,7 +169,7 @@ func TestStringEqual(t *testing.T) { for _, data := range testData { if !assert.True(t, StringEqual(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } @@ -185,7 +185,7 @@ func TestRegexMatch(t *testing.T) { for _, data := range testData { if !assert.True(t, RegexMatch(t, data.raw, data.expected)) { - t.Fail() + t.Fatal() } } } diff --git a/hrp/internal/builtin/utils.go b/hrp/internal/builtin/utils.go index 47654912..4d4dfb56 100644 --- a/hrp/internal/builtin/utils.go +++ b/hrp/internal/builtin/utils.go @@ -270,11 +270,12 @@ func loadFromCSV(path string) []map[string]interface{} { log.Error().Err(err).Msg("parse csv file failed") os.Exit(1) } + firstLine := content[0] // parameter names var result []map[string]interface{} for i := 1; i < len(content); i++ { row := make(map[string]interface{}) for j := 0; j < len(content[i]); j++ { - row[content[0][j]] = content[i][j] + row[firstLine[j]] = content[i][j] } result = append(result, row) } diff --git a/hrp/internal/har2case/core_test.go b/hrp/internal/har2case/core_test.go index 93fb5ef6..fae4a3f5 100644 --- a/hrp/internal/har2case/core_test.go +++ b/hrp/internal/har2case/core_test.go @@ -17,20 +17,20 @@ var ( func TestGenJSON(t *testing.T) { jsonPath, err := NewHAR(harPath).GenJSON() if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.NotEmpty(t, jsonPath) { - t.Fail() + t.Fatal() } } func TestGenYAML(t *testing.T) { yamlPath, err := NewHAR(harPath2).GenYAML() if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.NotEmpty(t, yamlPath) { - t.Fail() + t.Fatal() } } @@ -38,13 +38,13 @@ func TestLoadHAR(t *testing.T) { har := NewHAR(harPath) h, err := har.load() if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, "GET", h.Log.Entries[0].Request.Method) { - t.Fail() + t.Fatal() } if !assert.Equal(t, "POST", h.Log.Entries[1].Request.Method) { - t.Fail() + t.Fatal() } } @@ -53,18 +53,18 @@ func TestLoadHARWithProfile(t *testing.T) { har.SetProfile(profilePath) _, err := har.load() if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]interface{}{"Content-Type": "application/x-www-form-urlencoded"}, har.profile["headers"]) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]interface{}{"UserName": "debugtalk"}, har.profile["cookies"]) { - t.Fail() + t.Fatal() } } @@ -72,73 +72,73 @@ func TestMakeTestCase(t *testing.T) { har := NewHAR(harPath) tCase, err := har.makeTestCase() if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } // make request method if !assert.EqualValues(t, "GET", tCase.TestSteps[0].Request.Method) { - t.Fail() + t.Fatal() } if !assert.EqualValues(t, "POST", tCase.TestSteps[1].Request.Method) { - t.Fail() + t.Fatal() } // make request url if !assert.Equal(t, "https://postman-echo.com/get", tCase.TestSteps[0].Request.URL) { - t.Fail() + t.Fatal() } if !assert.Equal(t, "https://postman-echo.com/post", tCase.TestSteps[1].Request.URL) { - t.Fail() + t.Fatal() } // make request params if !assert.Equal(t, "HDnY8", tCase.TestSteps[0].Request.Params["foo1"]) { - t.Fail() + t.Fatal() } // make request cookies if !assert.NotEmpty(t, tCase.TestSteps[1].Request.Cookies["sails.sid"]) { - t.Fail() + t.Fatal() } // make request headers if !assert.Equal(t, "HttpRunnerPlus", tCase.TestSteps[0].Request.Headers["User-Agent"]) { - t.Fail() + t.Fatal() } if !assert.Equal(t, "postman-echo.com", tCase.TestSteps[0].Request.Headers["Host"]) { - t.Fail() + t.Fatal() } // make request data if !assert.Equal(t, nil, tCase.TestSteps[0].Request.Body) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]interface{}{"foo1": "HDnY8", "foo2": 12.3}, tCase.TestSteps[1].Request.Body) { - t.Fail() + t.Fatal() } if !assert.Equal(t, "foo1=HDnY8&foo2=12.3", tCase.TestSteps[2].Request.Body) { - t.Fail() + t.Fatal() } // make validators validator, ok := tCase.TestSteps[0].Validators[0].(hrp.Validator) if !ok || !assert.Equal(t, "status_code", validator.Check) { - t.Fail() + t.Fatal() } validator, ok = tCase.TestSteps[0].Validators[1].(hrp.Validator) if !ok || !assert.Equal(t, "headers.\"Content-Type\"", validator.Check) { - t.Fail() + t.Fatal() } validator, ok = tCase.TestSteps[0].Validators[2].(hrp.Validator) if !ok || !assert.Equal(t, "body.url", validator.Check) { - t.Fail() + t.Fatal() } } func TestGetFilenameWithoutExtension(t *testing.T) { filename := getFilenameWithoutExtension(harPath2) if !assert.Equal(t, "postman-echo", filename) { - t.Fail() + t.Fatal() } } @@ -154,13 +154,13 @@ func TestMakeRequestHeaders(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]string{ "Content-Type": "application/json; charset=utf-8", }, step.Request.Headers) { - t.Fail() + t.Fatal() } } @@ -177,13 +177,13 @@ func TestMakeRequestHeadersWithProfile(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]string{ "Content-Type": "application/x-www-form-urlencoded", }, step.Request.Headers) { - t.Fail() + t.Fatal() } } @@ -200,14 +200,14 @@ func TestMakeRequestCookies(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]string{ "abc": "123", "UserName": "leolee", }, step.Request.Cookies) { - t.Fail() + t.Fatal() } } @@ -225,13 +225,13 @@ func TestMakeRequestCookiesWithProfile(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]string{ "UserName": "debugtalk", }, step.Request.Cookies) { - t.Fail() + t.Fatal() } } @@ -251,11 +251,11 @@ func TestMakeRequestDataParams(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, "a=1&b=2", step.Request.Body) { - t.Fail() + t.Fatal() } } @@ -272,11 +272,11 @@ func TestMakeRequestDataJSON(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, map[string]interface{}{"a": "1", "b": "2"}, step.Request.Body) { - t.Fail() + t.Fatal() } } @@ -293,11 +293,11 @@ func TestMakeRequestDataTextEmpty(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, nil, step.Request.Body) { // TODO - t.Fail() + t.Fatal() } } @@ -320,11 +320,11 @@ func TestMakeValidate(t *testing.T) { } step, err := har.prepareTestStep(entry) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } validator, ok := step.Validators[0].(hrp.Validator) if !ok { - t.Fail() + t.Fatal() } if !assert.Equal(t, validator, hrp.Validator{ @@ -332,12 +332,12 @@ func TestMakeValidate(t *testing.T) { Expect: 200, Assert: "equals", Message: "assert response status code"}) { - t.Fail() + t.Fatal() } validator, ok = step.Validators[1].(hrp.Validator) if !ok { - t.Fail() + t.Fatal() } if !assert.Equal(t, validator, hrp.Validator{ @@ -345,12 +345,12 @@ func TestMakeValidate(t *testing.T) { Expect: "application/json; charset=utf-8", Assert: "equals", Message: "assert response header Content-Type"}) { - t.Fail() + t.Fatal() } validator, ok = step.Validators[2].(hrp.Validator) if !ok { - t.Fail() + t.Fatal() } if !assert.Equal(t, validator, hrp.Validator{ @@ -358,6 +358,6 @@ func TestMakeValidate(t *testing.T) { Expect: float64(200), // TODO Assert: "equals", Message: "assert response body Code"}) { - t.Fail() + t.Fatal() } } diff --git a/hrp/internal/scaffold/examples_test.go b/hrp/internal/scaffold/examples_test.go index 35ec4381..22daa768 100644 --- a/hrp/internal/scaffold/examples_test.go +++ b/hrp/internal/scaffold/examples_test.go @@ -10,20 +10,20 @@ func TestGenDemoExamples(t *testing.T) { os.RemoveAll(dir) err := CreateScaffold(dir, Go) if err != nil { - t.Fail() + t.Fatal() } dir = "../../../examples/demo-with-py-plugin" os.RemoveAll(dir) err = CreateScaffold(dir, Py) if err != nil { - t.Fail() + t.Fatal() } dir = "../../../examples/demo-without-plugin" os.RemoveAll(dir) err = CreateScaffold(dir, Ignore) if err != nil { - t.Fail() + t.Fatal() } } diff --git a/hrp/internal/scaffold/templates/pytest.ini b/hrp/internal/scaffold/templates/pytest.ini new file mode 100644 index 00000000..62fcbe9b --- /dev/null +++ b/hrp/internal/scaffold/templates/pytest.ini @@ -0,0 +1,6 @@ +[pytest] +addopts = -s +# https://docs.pytest.org/en/latest/how-to/output.html +junit_logging = all +junit_duration_report = total +log_cli = False \ No newline at end of file diff --git a/hrp/internal/sdk/client_test.go b/hrp/internal/sdk/client_test.go index 8c31cf47..e1044d47 100644 --- a/hrp/internal/sdk/client_test.go +++ b/hrp/internal/sdk/client_test.go @@ -25,6 +25,6 @@ func TestStructToUrlValues(t *testing.T) { } val := structToUrlValues(event) if val.Encode() != "ea=convert&ec=unittest&el=v0.3.0&ev=123" { - t.Fail() + t.Fatal() } } diff --git a/hrp/parser.go b/hrp/parser.go index 3a0d03bb..6941eaf7 100644 --- a/hrp/parser.go +++ b/hrp/parser.go @@ -454,7 +454,7 @@ func (p *Parser) ParseVariables(variables map[string]interface{}) (map[string]in return parsedVariables, nil } -type variableSet map[string]struct{} +type variableSet map[string]struct{} // TODO func extractVariables(raw interface{}) variableSet { rawValue := reflect.ValueOf(raw) diff --git a/hrp/parser_test.go b/hrp/parser_test.go index 10e843a7..ee0b6fb3 100644 --- a/hrp/parser_test.go +++ b/hrp/parser_test.go @@ -13,41 +13,41 @@ func TestBuildURL(t *testing.T) { url = buildURL("https://postman-echo.com", "/get") if !assert.Equal(t, url, "https://postman-echo.com/get") { - t.Fail() + t.Fatal() } url = buildURL("https://postman-echo.com", "get") if !assert.Equal(t, url, "https://postman-echo.com/get") { - t.Fail() + t.Fatal() } url = buildURL("https://postman-echo.com/", "/get") if !assert.Equal(t, url, "https://postman-echo.com/get") { - t.Fail() + t.Fatal() } url = buildURL("https://postman-echo.com/abc/", "/get?a=1&b=2") if !assert.Equal(t, url, "https://postman-echo.com/abc/get?a=1&b=2") { - t.Fail() + t.Fatal() } url = buildURL("https://postman-echo.com/abc", "get?a=1&b=2") if !assert.Equal(t, url, "https://postman-echo.com/abc/get?a=1&b=2") { - t.Fail() + t.Fatal() } // omit query string in base url url = buildURL("https://postman-echo.com/abc?x=6&y=9", "/get?a=1&b=2") if !assert.Equal(t, url, "https://postman-echo.com/abc/get?a=1&b=2") { - t.Fail() + t.Fatal() } url = buildURL("", "https://postman-echo.com/get") if !assert.Equal(t, url, "https://postman-echo.com/get") { - t.Fail() + t.Fatal() } // notice: step request url > config base url url = buildURL("https://postman-echo.com", "https://httpbin.org/get") if !assert.Equal(t, url, "https://httpbin.org/get") { - t.Fail() + t.Fatal() } } @@ -64,7 +64,7 @@ func TestRegexCompileVariable(t *testing.T) { for _, expr := range testData { varMatched := regexCompileVariable.FindStringSubmatch(expr) if !assert.Len(t, varMatched, 3) { - t.Fail() + t.Fatal() } } } @@ -81,7 +81,7 @@ func TestRegexCompileAbnormalVariable(t *testing.T) { for _, expr := range testData { varMatched := regexCompileVariable.FindStringSubmatch(expr) if !assert.Len(t, varMatched, 0) { - t.Fail() + t.Fatal() } } } @@ -99,7 +99,7 @@ func TestRegexCompileFunction(t *testing.T) { for _, expr := range testData { varMatched := regexCompileFunction.FindStringSubmatch(expr) if !assert.Len(t, varMatched, 3) { - t.Fail() + t.Fatal() } } } @@ -121,7 +121,7 @@ func TestRegexCompileAbnormalFunction(t *testing.T) { for _, expr := range testData { varMatched := regexCompileFunction.FindStringSubmatch(expr) if !assert.Len(t, varMatched, 0) { - t.Fail() + t.Fatal() } } } @@ -183,10 +183,10 @@ func TestParseDataStringWithVariables(t *testing.T) { for _, data := range testData { parsedData, err := parser.Parse(data.expr, variablesMapping) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, parsedData) { - t.Fail() + t.Fatal() } } } @@ -208,10 +208,10 @@ func TestParseDataStringWithUndefinedVariables(t *testing.T) { for _, data := range testData { parsedData, err := parser.Parse(data.expr, variablesMapping) if !assert.Error(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, parsedData) { - t.Fail() + t.Fatal() } } } @@ -253,10 +253,10 @@ func TestParseDataStringWithVariablesAbnormal(t *testing.T) { for _, data := range testData { parsedData, err := parser.Parse(data.expr, variablesMapping) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, parsedData) { - t.Fail() + t.Fatal() } } } @@ -284,10 +284,10 @@ func TestParseDataMapWithVariables(t *testing.T) { for _, data := range testData { parsedData, err := parser.Parse(data.expr, variablesMapping) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, parsedData) { - t.Fail() + t.Fatal() } } } @@ -318,10 +318,10 @@ func TestParseHeaders(t *testing.T) { for _, data := range testData { parsedHeaders, err := parser.ParseHeaders(data.rawHeaders, variablesMapping) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expectHeaders, parsedHeaders) { - t.Fail() + t.Fatal() } } } @@ -347,7 +347,7 @@ func TestMergeVariables(t *testing.T) { for _, data := range testData { mergedVariables := mergeVariables(data.stepVariables, data.configVariables) if !assert.Equal(t, data.expectVariables, mergedVariables) { - t.Fail() + t.Fatal() } } } @@ -383,7 +383,7 @@ func TestMergeMap(t *testing.T) { for _, data := range testData { mergedMap := mergeMap(data.m, data.overriddenMap) if !assert.Equal(t, data.expectMap, mergedMap) { - t.Fail() + t.Fatal() } } } @@ -414,7 +414,7 @@ func TestMergeSlices(t *testing.T) { for _, data := range testData { mergedSlice := mergeSlices(data.slice, data.overriddenSlice) if !assert.Equal(t, data.expectSlice, mergedSlice) { - t.Fail() + t.Fatal() } } } @@ -453,7 +453,7 @@ func TestMergeValidators(t *testing.T) { for _, data := range testData { mergedValidators := mergeValidators(data.validators, data.overriddenValidators) if !assert.Equal(t, data.expectValidators, mergedValidators) { - t.Fail() + t.Fatal() } } } @@ -464,35 +464,35 @@ func TestCallBuiltinFunction(t *testing.T) { // call function without arguments _, err := parser.CallFunc("get_timestamp") if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } // call function with one argument timeStart := time.Now() _, err = parser.CallFunc("sleep", 1) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Greater(t, time.Since(timeStart), time.Duration(1)*time.Second) { - t.Fail() + t.Fatal() } // call function with one argument result, err := parser.CallFunc("gen_random_string", 10) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, 10, len(result.(string))) { - t.Fail() + t.Fatal() } // call function with two argument result, err = parser.CallFunc("max", float64(10), 9.99) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, float64(10), result.(float64)) { - t.Fail() + t.Fatal() } } @@ -517,10 +517,10 @@ func TestLiteralEval(t *testing.T) { for _, data := range testData { value, err := literalEval(data.expr) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, value) { - t.Fail() + t.Fatal() } } } @@ -547,10 +547,10 @@ func TestParseFunctionArguments(t *testing.T) { for _, data := range testData { value, err := parseFunctionArguments(data.expr) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, value) { - t.Fail() + t.Fatal() } } } @@ -576,10 +576,10 @@ func TestParseDataStringWithFunctions(t *testing.T) { for _, data := range testData1 { value, err := parser.Parse(data.expr, variablesMapping) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, len(value.(string))) { - t.Fail() + t.Fatal() } } @@ -595,10 +595,10 @@ func TestParseDataStringWithFunctions(t *testing.T) { for _, data := range testData2 { value, err := parser.Parse(data.expr, variablesMapping) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expect, value) { - t.Fail() + t.Fatal() } } } @@ -619,7 +619,7 @@ func TestConvertString(t *testing.T) { for _, data := range testData { value := convertString(data.raw) if !assert.Equal(t, data.expect, value) { - t.Fail() + t.Fatal() } } } @@ -643,10 +643,10 @@ func TestParseVariables(t *testing.T) { for _, data := range testData { value, err := parser.ParseVariables(data.rawVars) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expectVars, value) { - t.Fail() + t.Fatal() } } } @@ -674,10 +674,10 @@ func TestParseVariablesAbnormal(t *testing.T) { for _, data := range testData { value, err := parser.ParseVariables(data.rawVars) if !assert.Error(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, data.expectVars, value) { - t.Fail() + t.Fatal() } } } @@ -710,7 +710,7 @@ func TestExtractVariables(t *testing.T) { } sort.Strings(varList) if !assert.Equal(t, data.expectVars, varList) { - t.Fail() + t.Fatal() } } } @@ -749,7 +749,7 @@ func TestFindallVariables(t *testing.T) { } sort.Strings(varList) if !assert.Equal(t, data.expectVars, varList) { - t.Fail() + t.Fatal() } } } diff --git a/hrp/plugin_test.go b/hrp/plugin_test.go index 612e40ae..26e74213 100644 --- a/hrp/plugin_test.go +++ b/hrp/plugin_test.go @@ -10,36 +10,36 @@ func TestLocateFile(t *testing.T) { // specify target file path _, err := locateFile(templatesDir+"plugin/debugtalk.go", "debugtalk.go") if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } // specify path with the same dir _, err = locateFile(templatesDir+"plugin/debugtalk.py", "debugtalk.go") if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } // specify target file path dir _, err = locateFile(templatesDir+"plugin/", "debugtalk.go") if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } // specify wrong path _, err = locateFile(".", "debugtalk.go") if !assert.Error(t, err) { - t.Fail() + t.Fatal() } _, err = locateFile("/abc", "debugtalk.go") if !assert.Error(t, err) { - t.Fail() + t.Fatal() } } func TestLocatePythonPlugin(t *testing.T) { _, err := locatePlugin(templatesDir + "plugin/debugtalk.py") if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } } @@ -49,6 +49,6 @@ func TestLocateGoPlugin(t *testing.T) { _, err := locatePlugin(templatesDir + "debugtalk.bin") if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } } diff --git a/hrp/response_test.go b/hrp/response_test.go index 49a32aa2..5b06ba5b 100644 --- a/hrp/response_test.go +++ b/hrp/response_test.go @@ -24,11 +24,11 @@ func TestSearchJmespath(t *testing.T) { resp.Body = io.NopCloser(strings.NewReader(testText)) respObj, err := newResponseObject(t, newParser(), &resp) if err != nil { - t.Fail() + t.Fatal() } for _, data := range testData { if !assert.Equal(t, data.expected, respObj.searchJmespath(data.raw)) { - t.Fail() + t.Fatal() } } } @@ -49,11 +49,11 @@ func TestSearchRegexp(t *testing.T) { resp.Body = io.NopCloser(strings.NewReader(testText)) respObj, err := newResponseObject(t, newParser(), &resp) if err != nil { - t.Fail() + t.Fatal() } for _, data := range testData { if !assert.Equal(t, data.expected, respObj.searchRegexp(data.raw)) { - t.Fail() + t.Fatal() } } } diff --git a/hrp/runner_test.go b/hrp/runner_test.go index 5ea57e51..9510a975 100644 --- a/hrp/runner_test.go +++ b/hrp/runner_test.go @@ -161,7 +161,7 @@ func TestRunCaseWithPluginJSON(t *testing.T) { err := NewRunner(nil).Run(&demoTestCaseWithPluginJSONPath) // hrp.Run(testCase) if err != nil { - t.Fail() + t.Fatal() } } @@ -171,7 +171,7 @@ func TestRunCaseWithPluginYAML(t *testing.T) { err := NewRunner(nil).Run(&demoTestCaseWithPluginYAMLPath) // hrp.Run(testCase) if err != nil { - t.Fail() + t.Fatal() } } @@ -181,7 +181,7 @@ func TestRunCaseWithRefAPI(t *testing.T) { err := NewRunner(nil).Run(&demoTestCaseWithRefAPIPath) if err != nil { - t.Fail() + t.Fatal() } testcase := &TestCase{ @@ -195,7 +195,7 @@ func TestRunCaseWithRefAPI(t *testing.T) { r := NewRunner(t) err = r.Run(testcase) if err != nil { - t.Fail() + t.Fatal() } } @@ -204,30 +204,30 @@ func TestLoadTestCases(t *testing.T) { tc := TestCasePath("../examples/demo-with-py-plugin/testcases/") testCases, err := loadTestCases(&tc) if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, len(testCases), 3) { - t.Fail() + t.Fatal() } // load test cases from folder path, including sub folders tc = TestCasePath("../examples/demo-with-py-plugin/") testCases, err = loadTestCases(&tc) if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, len(testCases), 3) { - t.Fail() + t.Fatal() } // load test cases from single file path tc = demoTestCaseWithPluginJSONPath testCases, err = loadTestCases(&tc) if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, 1, len(testCases)) { - t.Fail() + t.Fatal() } // load test cases from TestCase instance @@ -236,9 +236,9 @@ func TestLoadTestCases(t *testing.T) { } testCases, err = loadTestCases(testcase) if !assert.Nil(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, len(testCases), 1) { - t.Fail() + t.Fatal() } } diff --git a/hrp/testcase_test.go b/hrp/testcase_test.go index 2b0556fb..e49eccfe 100644 --- a/hrp/testcase_test.go +++ b/hrp/testcase_test.go @@ -156,21 +156,21 @@ func TestGenDemoTestCase(t *testing.T) { tCase := demoTestCaseWithPlugin.ToTCase() err := builtin.Dump2JSON(tCase, demoTestCaseWithPluginJSONPath.GetPath()) if err != nil { - t.Fail() + t.Fatal() } err = builtin.Dump2YAML(tCase, demoTestCaseWithPluginYAMLPath.GetPath()) if err != nil { - t.Fail() + t.Fatal() } tCase = demoTestCaseWithoutPlugin.ToTCase() err = builtin.Dump2JSON(tCase, demoTestCaseWithoutPluginJSONPath.GetPath()) if err != nil { - t.Fail() + t.Fatal() } err = builtin.Dump2YAML(tCase, demoTestCaseWithoutPluginYAMLPath.GetPath()) if err != nil { - t.Fail() + t.Fatal() } } @@ -179,24 +179,24 @@ func TestLoadCase(t *testing.T) { tcYAML := &TCase{} err := builtin.LoadFile(demoTestCaseWithPluginJSONPath.GetPath(), tcJSON) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } err = builtin.LoadFile(demoTestCaseWithPluginYAMLPath.GetPath(), tcYAML) if !assert.NoError(t, err) { - t.Fail() + t.Fatal() } if !assert.Equal(t, tcJSON.Config.Name, tcYAML.Config.Name) { - t.Fail() + t.Fatal() } if !assert.Equal(t, tcJSON.Config.BaseURL, tcYAML.Config.BaseURL) { - t.Fail() + t.Fatal() } if !assert.Equal(t, tcJSON.TestSteps[1].Name, tcYAML.TestSteps[1].Name) { - t.Fail() + t.Fatal() } if !assert.Equal(t, tcJSON.TestSteps[1].Request, tcYAML.TestSteps[1].Request) { - t.Fail() + t.Fatal() } } @@ -222,7 +222,7 @@ func TestConvertCheckExpr(t *testing.T) { } for _, expr := range exprs { if !assert.Equal(t, convertCheckExpr(expr.before), expr.after) { - t.Fail() + t.Fatal() } } }