From a647fe67b02ca29da727eee8191fa72c9c0447c5 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 11 Oct 2021 15:36:02 +0800 Subject: [PATCH] feat: add har2case command --- har2case/main.go | 57 +++++++++++++++++++++++++++++++++++++++++++ har2case/main_test.go | 24 ++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 har2case/main.go create mode 100644 har2case/main_test.go diff --git a/har2case/main.go b/har2case/main.go new file mode 100644 index 00000000..5a096476 --- /dev/null +++ b/har2case/main.go @@ -0,0 +1,57 @@ +package har2case + +import ( + "path/filepath" + + "github.com/httprunner/httpboomer" +) + +func NewHAR(path string) *HAR { + return &HAR{ + path: path, + } +} + +type HAR struct { + path string + filterStr string + excludeStr string +} + +func (h *HAR) GenJSON() (jsonPath string, err error) { + ext := filepath.Ext(h.path) + jsonPath = h.path[0:len(h.path)-len(ext)] + ".json" + + tCase := h.makeTestCase() + err = tCase.Dump2JSON(jsonPath) + return +} + +func (h *HAR) GenYAML() (yamlPath string, err error) { + ext := filepath.Ext(h.path) + yamlPath = h.path[0:len(h.path)-len(ext)] + ".yaml" + + tCase := h.makeTestCase() + err = tCase.Dump2YAML(yamlPath) + return +} + +func (h *HAR) makeTestCase() *httpboomer.TCase { + return &httpboomer.TCase{ + Config: *h.prepareConfig(), + TestSteps: h.prepareTestSteps(), + } +} + +func (h *HAR) prepareConfig() *httpboomer.TConfig { + return &httpboomer.TConfig{ + Name: "testcase description", + Variables: make(map[string]interface{}), + Verify: false, + } +} + +func (h *HAR) prepareTestSteps() []*httpboomer.TStep { + var steps []*httpboomer.TStep + return steps +} diff --git a/har2case/main_test.go b/har2case/main_test.go new file mode 100644 index 00000000..aaf6205e --- /dev/null +++ b/har2case/main_test.go @@ -0,0 +1,24 @@ +package har2case + +import ( + "log" + "os" + "testing" +) + +var harPath string + +func TestMain(m *testing.M) { + harPath = "demo.har" + + // run all tests + code := m.Run() + defer os.Exit(code) + + // teardown +} + +func TestGenJSON(t *testing.T) { + jsonPath, err := NewHAR(harPath).GenJSON() + log.Printf("jsonPath: %v, err: %v", jsonPath, err) +}