From 78bfc361ebb8ecda3919761bcca04f3955c210f9 Mon Sep 17 00:00:00 2001 From: Harsh4902 Date: Wed, 19 Mar 2025 22:44:04 +0530 Subject: [PATCH 1/2] chore: removed some unncessary null checks from 'test.go' Signed-off-by: Harsh4902 --- cmd/test.go | 17 ++++++++--------- go.mod | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/test.go b/cmd/test.go index 43c2b527..481140a6 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -28,8 +28,7 @@ import ( ) var ( - runnerChoices = map[string]bool{"HTTP": true, "SOAP_HTTP": true, "SOAP_UI": true, "POSTMAN": true, "OPEN_API_SCHEMA": true, "ASYNC_API_SCHEMA": true, "GRPC_PROTOBUF": true, "GRAPHQL_SCHEMA": true} - timeUnitChoices = map[string]bool{"milli": true, "sec": true, "min": true} + runnerChoices = map[string]bool{"HTTP": true, "SOAP_HTTP": true, "SOAP_UI": true, "POSTMAN": true, "OPEN_API_SCHEMA": true, "ASYNC_API_SCHEMA": true, "GRPC_PROTOBUF": true, "GRAPHQL_SCHEMA": true} ) func NewTestCommand() *cobra.Command { @@ -58,20 +57,20 @@ func NewTestCommand() *cobra.Command { os.Exit(1) } - serviceRef := os.Args[2] - testEndpoint := os.Args[3] - runnerType := os.Args[4] + serviceRef := args[0] + testEndpoint := args[1] + runnerType := args[2] // Validate presence and values of args. - if &serviceRef == nil || strings.HasPrefix(serviceRef, "-") { + if len(serviceRef) == 0 || strings.HasPrefix(serviceRef, "-") { fmt.Println("test command require args") os.Exit(1) } - if &testEndpoint == nil || strings.HasPrefix(testEndpoint, "-") { + if len(testEndpoint) == 0 || strings.HasPrefix(testEndpoint, "-") { fmt.Println("test command require args") os.Exit(1) } - if &runnerType == nil || strings.HasPrefix(runnerType, "-") { + if len(runnerType) == 0 || strings.HasPrefix(runnerType, "-") { fmt.Println("test command require args") os.Exit(1) } @@ -81,7 +80,7 @@ func NewTestCommand() *cobra.Command { } // Validate presence and values of flags. - if &waitFor == nil || (!strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min")) { + if len(waitFor) == 0 || (!strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min")) { fmt.Println("--waitFor format is wrong. Applying default 5sec") waitFor = "5sec" } diff --git a/go.mod b/go.mod index 9ee032f7..97941618 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/microcks/microcks-cli go 1.12 -require github.com/spf13/cobra v1.9.1 // indirect +require github.com/spf13/cobra v1.9.1 From 1eecebcda8fc1a09648bdbf79495841986a8afa9 Mon Sep 17 00:00:00 2001 From: Harsh4902 Date: Fri, 21 Mar 2025 12:12:11 +0530 Subject: [PATCH 2/2] chore: more clean up tasks Signed-off-by: Harsh4902 --- cmd/importURL.go | 2 +- cmd/test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/importURL.go b/cmd/importURL.go index 96b009e7..fcb19483 100644 --- a/cmd/importURL.go +++ b/cmd/importURL.go @@ -47,7 +47,7 @@ func NewImportURLCommand() *cobra.Command { os.Exit(1) } - specificationFiles := os.Args[2] + specificationFiles := args[0] // Collect optional HTTPS transport flags. if insecureTLS { diff --git a/cmd/test.go b/cmd/test.go index 481140a6..4fb20c67 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -80,9 +80,8 @@ func NewTestCommand() *cobra.Command { } // Validate presence and values of flags. - if len(waitFor) == 0 || (!strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min")) { + if !strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min") { fmt.Println("--waitFor format is wrong. Applying default 5sec") - waitFor = "5sec" } // Collect optional HTTPS transport flags.