From 04828b2984bf632a5badc4c20f401f470cda2c52 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:58:26 +0800 Subject: [PATCH] fix: error occour when the data parent dir non-exist (#291) --- cmd/run.go | 3 +- console/atest-ui/src/views/TestCase.vue | 34 ++++++------------ console/atest-ui/src/views/net-vue.ts | 48 +++++++++++++++++++++++++ console/atest-ui/src/views/net.ts | 26 ++++++++++---- extensions/collector/pkg/collector.go | 9 ++--- extensions/collector/pkg/exporter.go | 3 +- extensions/store-etcd/go.mod | 2 ++ extensions/store-etcd/go.sum | 3 ++ extensions/store-etcd/pkg/server.go | 4 +-- extensions/store-git/go.mod | 2 ++ extensions/store-git/go.sum | 3 ++ extensions/store-git/pkg/server.go | 3 +- extensions/store-mongodb/go.mod | 2 ++ extensions/store-mongodb/go.sum | 3 ++ extensions/store-orm/go.mod | 2 ++ extensions/store-orm/go.sum | 3 ++ extensions/store-s3/go.mod | 2 ++ extensions/store-s3/go.sum | 3 ++ pkg/generator/converter_jmeter.go | 4 +-- pkg/runner/grpc.go | 2 +- pkg/runner/kubernetes/client.go | 3 +- pkg/runner/reporter_prometheus.go | 4 +-- pkg/runner/runner_factory.go | 4 +-- pkg/runner/writer_pdf.go | 2 +- pkg/testing/case.go | 24 +++++++++++++ pkg/testing/loader.go | 24 +++++++++++++ pkg/testing/loader_file.go | 34 ++++++++++++++++-- pkg/testing/loader_file_test.go | 24 +++++++++++++ 28 files changed, 230 insertions(+), 50 deletions(-) create mode 100644 console/atest-ui/src/views/net-vue.ts diff --git a/cmd/run.go b/cmd/run.go index 172cfbe..ac7a0f3 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -28,6 +28,7 @@ import ( "context" "fmt" "io" + "log" "os" "strings" "sync" @@ -228,7 +229,7 @@ func (o *runOption) runSuiteWithDuration(loader testing.Loader) (err error) { defer sem.Release(1) defer wait.Done() defer func() { - fmt.Println("routing end with", time.Since(now)) + log.Println("routing end with", time.Since(now)) }() dataContext := getDefaultContext() diff --git a/console/atest-ui/src/views/TestCase.vue b/console/atest-ui/src/views/TestCase.vue index 06efea8..8ef6dce 100644 --- a/console/atest-ui/src/views/TestCase.vue +++ b/console/atest-ui/src/views/TestCase.vue @@ -7,6 +7,7 @@ import type { Pair, TestResult, TestCaseWithSuite } from './types' import { NewSuggestedAPIsQuery, CreateFilter, GetHTTPMethods, FlattenObject } from './types' import { Cache } from './cache' import { API } from './net' +import { UIAPI } from './net-vue' import type { TestCaseResponse } from './cache' import { useI18n } from 'vue-i18n' import { JSONPath } from 'jsonpath-plus' @@ -71,7 +72,7 @@ const sendRequest = async () => { parameters.value = [] requestLoading.value = false - ElMessage.error('Oops, ' + e) + UIAPI.ErrorTip(e) testResult.value.bodyObject = JSON.parse(e.body) testResult.value.originBodyObject = JSON.parse(e.body) }) @@ -96,9 +97,7 @@ function openParameterDialog() { API.GetTestSuite(props.suite, (e) => { parameters.value = e.param parameterDialogOpened.value = true - }, (e) => { - ElMessage.error('Oops, ' + e) - }) + }, UIAPI.ErrorTip) } function sendRequestWithParameter() { @@ -124,9 +123,7 @@ function generateCode() { } else { currentCodeContent.value = e.message } - }, (e) => { - ElMessage.error('Oops, ' + e) - }) + }, UIAPI.ErrorTip) } function copyCode() { @@ -268,23 +265,14 @@ watch(testCaseWithSuite, (after, before) => { const saveLoading = ref(false) function saveTestCase(tip: boolean = true) { - saveLoading.value = true - - API.UpdateTestCase(testCaseWithSuite.value, (e) => { + UIAPI.UpdateTestCase(testCaseWithSuite.value, (e) => { if (tip) { - if (e.ok) { - ElMessage({ - message: 'Saved.', - type: 'success' - }) - - needUpdate.value = false - } else { - ElMessage.error('Oops, ' + e.statusText) - } + ElMessage({ + message: 'Saved.', + type: 'success' + }) } - saveLoading.value = false - }) + }, UIAPI.ErrorTip, saveLoading) } function deleteTestCase() { @@ -306,7 +294,7 @@ function deleteTestCase() { // clean all the values testCaseWithSuite.value = emptyTestCaseWithSuite } else { - ElMessage.error('Oops, ' + e.statusText) + UIAPI.ErrorTip(e) } }) } diff --git a/console/atest-ui/src/views/net-vue.ts b/console/atest-ui/src/views/net-vue.ts new file mode 100644 index 0000000..c4d5d39 --- /dev/null +++ b/console/atest-ui/src/views/net-vue.ts @@ -0,0 +1,48 @@ +/** +MIT License + +Copyright (c) 2023 API Testing Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import { API } from './net' +import type { Ref } from 'vue' +import { ElMessage } from 'element-plus' + +function UpdateTestCase(testcase: any, + callback: (d: any) => void, errHandle?: (e: any) => void | null, + loadingRef?: Ref) { + API.UpdateTestCase(testcase, callback, errHandle, (e: boolean) => { + if (loadingRef) { + loadingRef.value = e + } + }) +} + +function ErrorTip(e: { + statusText:'' +}) { + ElMessage.error('Oops, ' + e.statusText) +} + +export const UIAPI = { + UpdateTestCase, + ErrorTip +} diff --git a/console/atest-ui/src/views/net.ts b/console/atest-ui/src/views/net.ts index d80cebe..1adb166 100644 --- a/console/atest-ui/src/views/net.ts +++ b/console/atest-ui/src/views/net.ts @@ -40,6 +40,13 @@ interface AppVersion { message: string } +function safeToggleFunc(toggle?: (e: boolean) => void) { + if (!toggle) { + return (e: boolean) => {} + } + return toggle +} + function GetVersion(callback: (v: AppVersion) => void) { const requestOptions = { method: 'POST', @@ -96,8 +103,8 @@ function UpdateTestSuite(suite: any, .then(callback).catch(errHandle) } -function GetTestSuite(name: string, callback: () => void, - errHandle: (e: any) => void) { +function GetTestSuite(name: string, + callback: (d: any) => void, errHandle: (e: any) => void) { const store = Cache.GetCurrentStore() const requestOptions = { method: 'POST', @@ -149,7 +156,7 @@ function ConvertTestSuite(suiteName: string, genertor: string, .then(callback).catch(errHandle) } -function ImportTestSuite(source: ImportSource, callback: () => void) { +function ImportTestSuite(source: ImportSource, callback: (d: any) => void) { const requestOptions = { method: 'POST', headers: { @@ -174,7 +181,7 @@ interface TestCase { } function CreateTestCase(testcase: TestCase, - callback: () => {}, errHandle?: (e: any) => void | null) { + callback: (d: any) => void, errHandle?: (e: any) => void | null) { const requestOptions = { method: 'POST', headers: { @@ -199,7 +206,8 @@ function CreateTestCase(testcase: TestCase, } function UpdateTestCase(testcase: any, - callback: () => {}, errHandle?: (e: any) => void | null) { + callback: (d: any) => void, errHandle?: (e: any) => void | null, + toggle?: (e: boolean) => void) { const requestOptions = { method: 'POST', headers: { @@ -208,9 +216,13 @@ function UpdateTestCase(testcase: any, }, body: JSON.stringify(testcase) } + safeToggleFunc(toggle)(true) fetch('/server.Runner/UpdateTestCase', requestOptions) .then(DefaultResponseProcess) .then(callback).catch(errHandle) + .finally(() => { + safeToggleFunc(toggle)(false) + }) } function GetTestCase(req: TestCase, @@ -227,7 +239,7 @@ function GetTestCase(req: TestCase, }) } fetch('/server.Runner/GetTestCase', requestOptions) - .then((response) => response.json()) + .then(DefaultResponseProcess) .then(callback).catch(errHandle) } @@ -402,4 +414,4 @@ export const API = { PopularHeaders, GetStores, DeleteStore, VerifyStore, getToken -} \ No newline at end of file +} diff --git a/extensions/collector/pkg/collector.go b/extensions/collector/pkg/collector.go index 5d48881..25b68c5 100644 --- a/extensions/collector/pkg/collector.go +++ b/extensions/collector/pkg/collector.go @@ -2,6 +2,7 @@ package pkg import ( "fmt" + "log" "net/http" "sync" ) @@ -64,19 +65,19 @@ func (c *Collects) Stop() { } func (c *Collects) handleEvents() { - fmt.Println("handle events") + log.Println("handle events") c.once.Do(func() { go func() { - fmt.Println("start handle events") + log.Println("start handle events") for { select { case key := <-c.signal: - fmt.Println("receive signal", key) + log.Println("receive signal", key) for _, e := range c.events { e(c.keys[key]) } case <-c.stopSignal: - fmt.Println("stop") + log.Println("stop") return } } diff --git a/extensions/collector/pkg/exporter.go b/extensions/collector/pkg/exporter.go index ac7fbfd..ed16ed4 100644 --- a/extensions/collector/pkg/exporter.go +++ b/extensions/collector/pkg/exporter.go @@ -3,6 +3,7 @@ package pkg import ( "fmt" "io" + "log" "strings" "github.com/linuxsuren/api-testing/pkg/testing" @@ -30,7 +31,7 @@ func NewSampleExporter(saveResponseBody bool) *SampleExporter { func (e *SampleExporter) Add(reqAndResp *RequestAndResponse) { r, resp := reqAndResp.Request, reqAndResp.Response - fmt.Println("receive", r.URL.Path) + log.Println("receive", r.URL.Path) req := atestpkg.Request{ API: r.URL.String(), Method: r.Method, diff --git a/extensions/store-etcd/go.mod b/extensions/store-etcd/go.mod index 920bfb1..40dc8af 100644 --- a/extensions/store-etcd/go.mod +++ b/extensions/store-etcd/go.mod @@ -89,9 +89,11 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.15.0 // indirect golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect diff --git a/extensions/store-etcd/go.sum b/extensions/store-etcd/go.sum index 00ddd8d..f00e56b 100644 --- a/extensions/store-etcd/go.sum +++ b/extensions/store-etcd/go.sum @@ -1157,6 +1157,8 @@ golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I= golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw= golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1421,6 +1423,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/extensions/store-etcd/pkg/server.go b/extensions/store-etcd/pkg/server.go index aaf5978..35c9298 100644 --- a/extensions/store-etcd/pkg/server.go +++ b/extensions/store-etcd/pkg/server.go @@ -27,7 +27,7 @@ package pkg import ( "context" "errors" - "fmt" + "log" "time" "github.com/linuxsuren/api-testing/pkg/server" @@ -291,7 +291,7 @@ func saveTestSuite(ctx context.Context, cli SimpleKV, suite *testing.TestSuite) var data []byte if data, err = testing.ToYAML(suite); err == nil { _, err = cli.Put(ctx, getKey(suite.Name), string(data)) - fmt.Println("save to etcd", err) + log.Println("save to etcd", err) } return } diff --git a/extensions/store-git/go.mod b/extensions/store-git/go.mod index fc61805..c198fb4 100644 --- a/extensions/store-git/go.mod +++ b/extensions/store-git/go.mod @@ -107,10 +107,12 @@ require ( golang.org/x/crypto v0.15.0 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.12.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/extensions/store-git/go.sum b/extensions/store-git/go.sum index 3cd25c1..05e2ef3 100644 --- a/extensions/store-git/go.sum +++ b/extensions/store-git/go.sum @@ -456,6 +456,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -620,6 +622,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/extensions/store-git/pkg/server.go b/extensions/store-git/pkg/server.go index 85ee12c..6941e67 100644 --- a/extensions/store-git/pkg/server.go +++ b/extensions/store-git/pkg/server.go @@ -29,6 +29,7 @@ import ( "errors" "fmt" "io" + "log" "os" "path" "time" @@ -62,7 +63,7 @@ func (s *gitClient) loadCache(ctx context.Context) (opt *gitOptions, err error) branch := "master" repoAddr := opt.cloneOptions.URL configDir := opt.cache - fmt.Println("load cache from", repoAddr) + log.Println("load cache from", repoAddr) if ok, _ := util.PathExists(configDir); ok { var repo *git.Repository diff --git a/extensions/store-mongodb/go.mod b/extensions/store-mongodb/go.mod index 0f10fcb..714093a 100644 --- a/extensions/store-mongodb/go.mod +++ b/extensions/store-mongodb/go.mod @@ -84,9 +84,11 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.15.0 // indirect golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/grpc v1.57.0 // indirect diff --git a/extensions/store-mongodb/go.sum b/extensions/store-mongodb/go.sum index 53c7a8b..0b58c5b 100644 --- a/extensions/store-mongodb/go.sum +++ b/extensions/store-mongodb/go.sum @@ -421,6 +421,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -572,6 +574,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/extensions/store-orm/go.mod b/extensions/store-orm/go.mod index 64b0def..12d553d 100644 --- a/extensions/store-orm/go.mod +++ b/extensions/store-orm/go.mod @@ -86,9 +86,11 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.15.0 // indirect golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/grpc v1.57.0 // indirect diff --git a/extensions/store-orm/go.sum b/extensions/store-orm/go.sum index 01b5900..512847d 100644 --- a/extensions/store-orm/go.sum +++ b/extensions/store-orm/go.sum @@ -413,6 +413,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -562,6 +564,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/extensions/store-s3/go.mod b/extensions/store-s3/go.mod index 9962237..1634853 100644 --- a/extensions/store-s3/go.mod +++ b/extensions/store-s3/go.mod @@ -84,9 +84,11 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.15.0 // indirect golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/grpc v1.59.0 // indirect diff --git a/extensions/store-s3/go.sum b/extensions/store-s3/go.sum index 1e87d7a..efee423 100644 --- a/extensions/store-s3/go.sum +++ b/extensions/store-s3/go.sum @@ -414,6 +414,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -565,6 +567,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/pkg/generator/converter_jmeter.go b/pkg/generator/converter_jmeter.go index ec437c1..356ea41 100644 --- a/pkg/generator/converter_jmeter.go +++ b/pkg/generator/converter_jmeter.go @@ -26,7 +26,7 @@ package generator import ( "encoding/xml" - "fmt" + "log" "net/url" "github.com/linuxsuren/api-testing/pkg/testing" @@ -60,7 +60,7 @@ func (c *jmeterConverter) buildJmeterTestPlan(testSuite *testing.TestSuite) (res for _, item := range testSuite.Items { item.Request.RenderAPI(testSuite.API) if reqRenderErr := item.Request.Render(emptyCtx, ""); reqRenderErr != nil { - fmt.Println("Error rendering request: ", reqRenderErr) + log.Println("Error rendering request: ", reqRenderErr) } api, err := url.Parse(item.Request.API) diff --git a/pkg/runner/grpc.go b/pkg/runner/grpc.go index f121b1a..af81c4a 100644 --- a/pkg/runner/grpc.go +++ b/pkg/runner/grpc.go @@ -314,7 +314,7 @@ func getMethodDescriptor(ctx context.Context, r *gRPCTestCaseRunner, testcase *t var dp protoreflect.Descriptor // if fd, ok := r.fdCache.Load(fullname.Parent()); ok { - // fmt.Println("hit cache",fullname) + // log.Println("hit cache",fullname) // return getMdFromFd(fd.(protoreflect.FileDescriptor), fullname) // } diff --git a/pkg/runner/kubernetes/client.go b/pkg/runner/kubernetes/client.go index 5ae792e..6e5ff55 100644 --- a/pkg/runner/kubernetes/client.go +++ b/pkg/runner/kubernetes/client.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "log" "net/http" "os" "strings" @@ -85,7 +86,7 @@ type defaultResourceValidator struct { // Exist returns true if the specific resource exist func (v *defaultResourceValidator) Exist() bool { if v.err != nil { - fmt.Println(v.err) + log.Println(v.err) return false } return v.data != nil && len(v.data) > 0 diff --git a/pkg/runner/reporter_prometheus.go b/pkg/runner/reporter_prometheus.go index e60f619..517394f 100644 --- a/pkg/runner/reporter_prometheus.go +++ b/pkg/runner/reporter_prometheus.go @@ -25,7 +25,7 @@ SOFTWARE. package runner import ( - "fmt" + "log" "sync" "github.com/prometheus/client_golang/prometheus" @@ -91,7 +91,7 @@ func (w *prometheusReporter) PutRecord(record *ReportRecord) { } if err := pusher.Push(); err != nil { - fmt.Println("Could not push completion time to Pushgateway:", err) + log.Println("Could not push completion time to Pushgateway:", err) } }() if w.sync { diff --git a/pkg/runner/runner_factory.go b/pkg/runner/runner_factory.go index 42ba785..09737b8 100644 --- a/pkg/runner/runner_factory.go +++ b/pkg/runner/runner_factory.go @@ -21,7 +21,7 @@ SOFTWARE. package runner import ( - "fmt" + "log" "strings" "github.com/linuxsuren/api-testing/pkg/testing" @@ -40,7 +40,7 @@ func GetTestSuiteRunner(suite *testing.TestSuite) TestCaseRunner { case "trpc": return NewTRPCTestCaseRunner(suite.API, *suite.Spec.RPC, client.New()) default: - fmt.Println("unknown test suite, try to use HTTP runner") + log.Println("unknown test suite, try to use HTTP runner") } } diff --git a/pkg/runner/writer_pdf.go b/pkg/runner/writer_pdf.go index 6f9ef74..47ef772 100644 --- a/pkg/runner/writer_pdf.go +++ b/pkg/runner/writer_pdf.go @@ -51,7 +51,7 @@ func (w *pdfResultWriter) Output(result []ReportResult) (err error) { pdf := gopdf.GoPdf{} pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4}) - fmt.Println(findfont.List()[len(findfont.List())-1]) + log.Println(findfont.List()[len(findfont.List())-1]) fontPath, err := findfont.Find("DejaVuSerif.ttf") if err != nil { panic(err) diff --git a/pkg/testing/case.go b/pkg/testing/case.go index 973e0e1..fd45104 100644 --- a/pkg/testing/case.go +++ b/pkg/testing/case.go @@ -1,3 +1,27 @@ +/** +MIT License + +Copyright (c) 2023 API Testing Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + package testing import "sort" diff --git a/pkg/testing/loader.go b/pkg/testing/loader.go index c5c0226..22915b1 100644 --- a/pkg/testing/loader.go +++ b/pkg/testing/loader.go @@ -1,3 +1,27 @@ +/** +MIT License + +Copyright (c) 2023 API Testing Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + package testing // Loader is an interface for test cases loader diff --git a/pkg/testing/loader_file.go b/pkg/testing/loader_file.go index 031a7cb..2445d1b 100644 --- a/pkg/testing/loader_file.go +++ b/pkg/testing/loader_file.go @@ -1,3 +1,27 @@ +/** +MIT License + +Copyright (c) 2023 API Testing Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + package testing import ( @@ -117,7 +141,7 @@ func (l *fileLoader) Put(item string) (err error) { if files, err = filepath.Glob(pattern); err == nil { l.paths = append(l.paths, files...) } - fmt.Println(pattern, "pattern", len(files)) + log.Println(pattern, "pattern", len(files)) } return } @@ -189,9 +213,15 @@ func (l *fileLoader) CreateSuite(name, api string) (err error) { if l.parent == "" { l.parent = path.Dir(absPath) } + + if err = os.MkdirAll(l.parent, 0755); err != nil { + err = fmt.Errorf("failed to create %q", l.parent) + return + } + newSuiteFile := path.Join(l.parent, fmt.Sprintf("%s.yaml", name)) if newSuiteFile, err = filepath.Abs(newSuiteFile); err == nil { - fmt.Println("new suite file:", newSuiteFile) + log.Println("new suite file:", newSuiteFile) suite := &TestSuite{ Name: name, diff --git a/pkg/testing/loader_file_test.go b/pkg/testing/loader_file_test.go index b39adaf..5d4b703 100644 --- a/pkg/testing/loader_file_test.go +++ b/pkg/testing/loader_file_test.go @@ -1,3 +1,27 @@ +/** +MIT License + +Copyright (c) 2023 API Testing Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + package testing_test import (