From c29f85bc640ba17bc5977f8ab3aef69ea1ec1abc Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 20 Sep 2021 10:59:37 +0800 Subject: [PATCH] feat: support nested testcase in teststep --- models.go | 1 + runner_test.go | 1 + testcase.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 testcase.go diff --git a/models.go b/models.go index 502ca9db..696b8f2c 100644 --- a/models.go +++ b/models.go @@ -50,6 +50,7 @@ type TValidator struct { type TStep struct { Name string `json:"name"` Request *TRequest `json:"request"` + TestCase *TestCase `json:"testcase"` Variables Variables `json:"variables"` SetupHooks []string `json:"setup_hooks"` TeardownHooks []string `json:"teardown_hooks"` diff --git a/runner_test.go b/runner_test.go index 57220114..eba1565d 100644 --- a/runner_test.go +++ b/runner_test.go @@ -21,6 +21,7 @@ func TestHttpRunner(t *testing.T) { Validate(). AssertEqual("status_code", 200, "check status code"). AssertEqual("body.\"user-agent\"", "python-requests", "check User-Agent"), + RunTestCase("TestCase3").WithVariables(Variables{"var1": "value1"}), }, } testcase2 := &TestCase{ diff --git a/testcase.go b/testcase.go new file mode 100644 index 00000000..894ef6f2 --- /dev/null +++ b/testcase.go @@ -0,0 +1,29 @@ +package httpboomer + +func RunTestCase(name string) *TestCase { + return &TestCase{ + Config: TConfig{ + Name: name, + }, + } +} + +func (tc *TestCase) WithVariables(variables Variables) *TestCase { + tc.Config.Variables = variables + return tc +} + +func (tc *TestCase) ToStruct() *TStep { + return &TStep{ + TestCase: tc, + } +} + +func (tc *TestCase) Run() error { + for _, step := range tc.TestSteps { + if err := step.Run(); err != nil { + return err + } + } + return nil +}