diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7c1e1b114..d260cb82b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,16 +20,16 @@ jobs: steps: - uses: actions/checkout@v2 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.40.1 + uses: golangci/golangci-lint-action@v3 + # with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + # version: v1.40.1 # Optional: working directory, useful for monorepos # working-directory: somedir # Optional: golangci-lint command line arguments. - args: --disable=staticcheck + # args: --disable=staticcheck # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true diff --git a/build/make.go b/build/make.go index 08d95f8db..68975cf96 100644 --- a/build/make.go +++ b/build/make.go @@ -58,7 +58,7 @@ func runProcess(command string, arg ...string) { func runCommand(command string, arg ...string) (string, error) { cmd := exec.Command(command, arg...) bytes, err := cmd.Output() - return strings.TrimSpace(fmt.Sprintf("%s", bytes)), err + return strings.TrimSpace(string(bytes)), err } var buildMetadata string @@ -152,15 +152,15 @@ var certFile = flag.String("certFile", "", "Should be passed for signing the win // Each target name is the directory name var ( platformEnvs = []map[string]string{ - map[string]string{GOARCH: ARM64, GOOS: darwin, CGO_ENABLED: "0"}, - map[string]string{GOARCH: X86_64, GOOS: darwin, CGO_ENABLED: "0"}, - map[string]string{GOARCH: X86, GOOS: linux, CGO_ENABLED: "0"}, - map[string]string{GOARCH: X86_64, GOOS: linux, CGO_ENABLED: "0"}, - map[string]string{GOARCH: ARM64, GOOS: linux, CGO_ENABLED: "0"}, - map[string]string{GOARCH: X86, GOOS: freebsd, CGO_ENABLED: "0"}, - map[string]string{GOARCH: X86_64, GOOS: freebsd, CGO_ENABLED: "0"}, - map[string]string{GOARCH: X86, GOOS: windows, CC: "i586-mingw32-gcc", CGO_ENABLED: "1"}, - map[string]string{GOARCH: X86_64, GOOS: windows, CC: "x86_64-w64-mingw32-gcc", CGO_ENABLED: "1"}, + {GOARCH: ARM64, GOOS: darwin, CGO_ENABLED: "0"}, + {GOARCH: X86_64, GOOS: darwin, CGO_ENABLED: "0"}, + {GOARCH: X86, GOOS: linux, CGO_ENABLED: "0"}, + {GOARCH: X86_64, GOOS: linux, CGO_ENABLED: "0"}, + {GOARCH: ARM64, GOOS: linux, CGO_ENABLED: "0"}, + {GOARCH: X86, GOOS: freebsd, CGO_ENABLED: "0"}, + {GOARCH: X86_64, GOOS: freebsd, CGO_ENABLED: "0"}, + {GOARCH: X86, GOOS: windows, CC: "i586-mingw32-gcc", CGO_ENABLED: "1"}, + {GOARCH: X86_64, GOOS: windows, CC: "x86_64-w64-mingw32-gcc", CGO_ENABLED: "1"}, } osDistroMap = map[string]distroFunc{windows: createWindowsDistro, linux: createLinuxPackage, freebsd: createLinuxPackage, darwin: createDarwinPackage} ) diff --git a/conn/connectionHandler.go b/conn/connectionHandler.go index 24a1e146a..72195e21a 100644 --- a/conn/connectionHandler.go +++ b/conn/connectionHandler.go @@ -13,7 +13,11 @@ import ( "time" "github.com/getgauge/gauge/logger" - "github.com/golang/protobuf/proto" + // github.com/golang/protobuf/proto is deprecated, however this package is used by the legacy API + // which is consumed only by IntelliJ IDEA presently. Since IDEA does not plan to implement LSP + // gauge will have to keep this alive. Upgrading to google.golang.org/protobuf/proto is not a drop in change + // since the newer library does not support DecodeVarint. The whole message handling will need to be refactored. + "github.com/golang/protobuf/proto" //nolint:staticcheck ) type messageHandler interface { diff --git a/conn/network.go b/conn/network.go index b14fcd6fc..5ba7fe541 100644 --- a/conn/network.go +++ b/conn/network.go @@ -18,7 +18,12 @@ import ( "github.com/getgauge/common" "github.com/getgauge/gauge-proto/go/gauge_messages" "github.com/getgauge/gauge/logger" - "github.com/golang/protobuf/proto" + + // github.com/golang/protobuf/proto is deprecated, however this package is used by the legacy API + // which is consumed only by IntelliJ IDEA presently. Since IDEA does not plan to implement LSP + // gauge will have to keep this alive. Upgrading to google.golang.org/protobuf/proto is not a drop in change + // since the newer library does not support DecodeVarint. The whole message handling will need to be refactored. + "github.com/golang/protobuf/proto" //nolint:staticcheck ) type response struct { diff --git a/conn/network_test.go b/conn/network_test.go index 2013490f4..3273c0dfa 100644 --- a/conn/network_test.go +++ b/conn/network_test.go @@ -15,7 +15,12 @@ import ( "time" "github.com/getgauge/gauge-proto/go/gauge_messages" - "github.com/golang/protobuf/proto" + + // github.com/golang/protobuf/proto is deprecated, however this package is used by the legacy API + // which is consumed only by IntelliJ IDEA presently. Since IDEA does not plan to implement LSP + // gauge will have to keep this alive. Upgrading to google.golang.org/protobuf/proto is not a drop in change + // since the newer library does not support DecodeVarint. The whole message handling will need to be refactored. + "github.com/golang/protobuf/proto" //nolint:staticcheck ) var id int64 diff --git a/execution/parallelGrpcExecution.go b/execution/parallelGrpcExecution.go index 324fcc636..2d0e74c3f 100644 --- a/execution/parallelGrpcExecution.go +++ b/execution/parallelGrpcExecution.go @@ -61,7 +61,6 @@ func (e *parallelExecution) notifyBeforeSuite() { res := e.runners[0].ExecuteAndGetStatus(m) e.suiteResult.PreHookMessages = res.Message e.suiteResult.PreHookScreenshotFiles = res.ScreenshotFiles - e.suiteResult.PreHookScreenshots = res.Screenshots if res.GetFailed() { result.AddPreHook(e.suiteResult, res) } @@ -80,7 +79,6 @@ func (e *parallelExecution) notifyAfterSuite() { res := e.runners[0].ExecuteAndGetStatus(m) e.suiteResult.PostHookMessages = res.Message e.suiteResult.PostHookScreenshotFiles = res.ScreenshotFiles - e.suiteResult.PostHookScreenshots = res.Screenshots if res.GetFailed() { result.AddPostHook(e.suiteResult, res) } diff --git a/execution/result/result.go b/execution/result/result.go index 95e4eb64d..6186c93c7 100644 --- a/execution/result/result.go +++ b/execution/result/result.go @@ -32,7 +32,6 @@ func GetProtoHookFailure(executionResult *gauge_messages.ProtoExecutionResult) * return &gauge_messages.ProtoHookFailure{ StackTrace: executionResult.StackTrace, ErrorMessage: executionResult.ErrorMessage, - FailureScreenshot: executionResult.FailureScreenshot, FailureScreenshotFile: executionResult.FailureScreenshotFile, TableRowIndex: -1, } diff --git a/execution/result/scenarioResult.go b/execution/result/scenarioResult.go index 512741ca2..40fa5a28f 100644 --- a/execution/result/scenarioResult.go +++ b/execution/result/scenarioResult.go @@ -24,7 +24,6 @@ func NewScenarioResult(sce *gauge_messages.ProtoScenario) *ScenarioResult { // SetFailure sets the scenarioResult as failed func (s ScenarioResult) SetFailure() { s.ProtoScenario.ExecutionStatus = gauge_messages.ExecutionStatus_FAILED - s.ProtoScenario.Failed = true } // GetFailed returns the state of the scenario result diff --git a/execution/scenarioExecutor.go b/execution/scenarioExecutor.go index ee51acb8a..d136c7db5 100644 --- a/execution/scenarioExecutor.go +++ b/execution/scenarioExecutor.go @@ -47,8 +47,7 @@ func (e *scenarioExecutor) execute(i gauge.Item, r result.Result) { scenario := i.(*gauge.Scenario) scenarioResult := r.(*result.ScenarioResult) scenarioResult.ProtoScenario.ExecutionStatus = gauge_messages.ExecutionStatus_PASSED - scenarioResult.ProtoScenario.Skipped = false - if(e.runner.Info().Killed){ + if e.runner.Info().Killed { e.errMap.ScenarioErrs[scenario] = append([]error{errors.New("skipped Reason: Runner is not alive")}, e.errMap.ScenarioErrs[scenario]...) setSkipInfoInResult(scenarioResult, scenario, e.errMap) return @@ -106,7 +105,6 @@ func (e *scenarioExecutor) handleScenarioDataStoreFailure(scenarioResult *result func setSkipInfoInResult(scenarioResult *result.ScenarioResult, scenario *gauge.Scenario, errMap *gauge.BuildErrors) { scenarioResult.ProtoScenario.ExecutionStatus = gauge_messages.ExecutionStatus_SKIPPED - scenarioResult.ProtoScenario.Skipped = true var errs []string for _, err := range errMap.ScenarioErrs[scenario] { errs = append(errs, err.Error()) @@ -121,7 +119,6 @@ func (e *scenarioExecutor) notifyBeforeScenarioHook(scenarioResult *result.Scena res := executeHook(message, scenarioResult, e.runner) scenarioResult.ProtoScenario.PreHookMessages = res.Message scenarioResult.ProtoScenario.PreHookScreenshotFiles = res.ScreenshotFiles - scenarioResult.ProtoScenario.PreHookScreenshots = res.Screenshots if res.GetFailed() { setScenarioFailure(e.currentExecutionInfo) handleHookFailure(scenarioResult, res, result.AddPreHook) @@ -136,7 +133,6 @@ func (e *scenarioExecutor) notifyAfterScenarioHook(scenarioResult *result.Scenar res := executeHook(message, scenarioResult, e.runner) scenarioResult.ProtoScenario.PostHookMessages = res.Message scenarioResult.ProtoScenario.PostHookScreenshotFiles = res.ScreenshotFiles - scenarioResult.ProtoScenario.PostHookScreenshots = res.Screenshots if res.GetFailed() { setScenarioFailure(e.currentExecutionInfo) handleHookFailure(scenarioResult, res, result.AddPostHook) diff --git a/execution/simpleExecution.go b/execution/simpleExecution.go index 49348ace4..915e0bd53 100644 --- a/execution/simpleExecution.go +++ b/execution/simpleExecution.go @@ -56,13 +56,13 @@ func newSimpleExecution(executionInfo *executionInfo, combineDataTableSpecs, ski } return &simpleExecution{ - manifest: executionInfo.manifest, - specCollection: executionInfo.specs, - runner: executionInfo.runner, - pluginHandler: executionInfo.pluginHandler, - errMaps: executionInfo.errMaps, - stream: executionInfo.stream, - skipSuiteEvents: skipSuiteEvents, + manifest: executionInfo.manifest, + specCollection: executionInfo.specs, + runner: executionInfo.runner, + pluginHandler: executionInfo.pluginHandler, + errMaps: executionInfo.errMaps, + stream: executionInfo.stream, + skipSuiteEvents: skipSuiteEvents, currentExecutionInfo: ei, } } @@ -142,7 +142,6 @@ func (e *simpleExecution) executeSpecs(sc *gauge.SpecCollection) (results []*res res.AddPreHook(&gauge_messages.ProtoHookFailure{ StackTrace: preHook.StackTrace, ErrorMessage: preHook.ErrorMessage, - FailureScreenshot: preHook.FailureScreenshot, FailureScreenshotFile: preHook.FailureScreenshotFile, TableRowIndex: preHook.TableRowIndex, }) @@ -151,7 +150,6 @@ func (e *simpleExecution) executeSpecs(sc *gauge.SpecCollection) (results []*res res.AddPostHook(&gauge_messages.ProtoHookFailure{ StackTrace: postHook.StackTrace, ErrorMessage: postHook.ErrorMessage, - FailureScreenshot: postHook.FailureScreenshot, FailureScreenshotFile: postHook.FailureScreenshotFile, TableRowIndex: postHook.TableRowIndex, }) @@ -168,7 +166,6 @@ func (e *simpleExecution) notifyBeforeSuite() { res := e.executeHook(m) e.suiteResult.PreHookMessages = res.Message e.suiteResult.PreHookScreenshotFiles = res.ScreenshotFiles - e.suiteResult.PreHookScreenshots = res.Screenshots if res.GetFailed() { handleHookFailure(e.suiteResult, res, result.AddPreHook) } @@ -182,7 +179,6 @@ func (e *simpleExecution) notifyAfterSuite() { res := e.executeHook(m) e.suiteResult.PostHookMessages = res.Message e.suiteResult.PostHookScreenshotFiles = res.ScreenshotFiles - e.suiteResult.PostHookScreenshots = res.Screenshots if res.GetFailed() { handleHookFailure(e.suiteResult, res, result.AddPostHook) } diff --git a/execution/simpleExecution_test.go b/execution/simpleExecution_test.go index 25caca347..52d9bb29a 100644 --- a/execution/simpleExecution_test.go +++ b/execution/simpleExecution_test.go @@ -186,60 +186,6 @@ func TestExecuteSpecsShouldAddsAfterSpecHookFailureScreenshotFile(t *testing.T) } } -func TestExecuteSpecsShouldAddsBeforeSpecHookFailureScreenshotBytes(t *testing.T) { - r := &mockRunner{} - h := &mockPluginHandler{NotifyPluginsfunc: func(m *gauge_messages.Message) {}, GracefullyKillPluginsfunc: func() {}} - r.ExecuteAndGetStatusFunc = func(m *gauge_messages.Message) *gauge_messages.ProtoExecutionResult { - if m.MessageType == gauge_messages.Message_SpecExecutionStarting { - return &gauge_messages.ProtoExecutionResult{ - Failed: true, - ExecutionTime: 10, - FailureScreenshot: []byte("before spec hook failure screenshot byte"), - } - } - return &gauge_messages.ProtoExecutionResult{} - } - ei := &executionInfo{runner: r, pluginHandler: h, errMaps: &gauge.BuildErrors{}} - simpleExecution := newSimpleExecution(ei, false, false) - specsC := createSpecCollection() - simpleExecution.suiteResult = result.NewSuiteResult(ExecuteTags, simpleExecution.startTime) - specResult := simpleExecution.executeSpecs(specsC) - - actualScreenshotBytes := specResult[0].ProtoSpec.PreHookFailures[0].FailureScreenshot - expectedScreenshotBytes := "before spec hook failure screenshot byte" - - if string(actualScreenshotBytes) != expectedScreenshotBytes { - t.Errorf("Expected `%s` screenshot, got : %s", expectedScreenshotBytes, actualScreenshotBytes) - } -} - -func TestExecuteSpecsShouldAddsAfterSpecHookFailureScreenshotBytes(t *testing.T) { - r := &mockRunner{} - h := &mockPluginHandler{NotifyPluginsfunc: func(m *gauge_messages.Message) {}, GracefullyKillPluginsfunc: func() {}} - r.ExecuteAndGetStatusFunc = func(m *gauge_messages.Message) *gauge_messages.ProtoExecutionResult { - if m.MessageType == gauge_messages.Message_SpecExecutionEnding { - return &gauge_messages.ProtoExecutionResult{ - Failed: true, - ExecutionTime: 10, - FailureScreenshot: []byte("after spec hook failure screenshot bytes"), - } - } - return &gauge_messages.ProtoExecutionResult{} - } - ei := &executionInfo{runner: r, pluginHandler: h, errMaps: &gauge.BuildErrors{}} - simpleExecution := newSimpleExecution(ei, false, false) - specsC := createSpecCollection() - simpleExecution.suiteResult = result.NewSuiteResult(ExecuteTags, simpleExecution.startTime) - specResult := simpleExecution.executeSpecs(specsC) - - actualScreenshotBytes := specResult[0].ProtoSpec.PostHookFailures[0].FailureScreenshot - expectedScreenshotBytes := "after spec hook failure screenshot bytes" - - if string(actualScreenshotBytes) != expectedScreenshotBytes { - t.Errorf("Expected `%s` screenshot, got : %s", expectedScreenshotBytes, actualScreenshotBytes) - } -} - func createSpecCollection() *gauge.SpecCollection { var specs []*gauge.Specification specs = append(specs, &gauge.Specification{ diff --git a/execution/specExecutor.go b/execution/specExecutor.go index 50eab0f8b..2f27be6d3 100644 --- a/execution/specExecutor.go +++ b/execution/specExecutor.go @@ -177,7 +177,6 @@ func (e *specExecutor) notifyBeforeSpecHook() { res := executeHook(m, e.specResult, e.runner) e.specResult.ProtoSpec.PreHookMessages = res.Message e.specResult.ProtoSpec.PreHookScreenshotFiles = res.ScreenshotFiles - e.specResult.ProtoSpec.PreHookScreenshots = res.Screenshots if res.GetFailed() { setSpecFailure(e.currentExecutionInfo) handleHookFailure(e.specResult, res, result.AddPreHook) @@ -193,7 +192,6 @@ func (e *specExecutor) notifyAfterSpecHook() { res := executeHook(m, e.specResult, e.runner) e.specResult.ProtoSpec.PostHookMessages = res.Message e.specResult.ProtoSpec.PostHookScreenshotFiles = res.ScreenshotFiles - e.specResult.ProtoSpec.PostHookScreenshots = res.Screenshots if res.GetFailed() { setSpecFailure(e.currentExecutionInfo) handleHookFailure(e.specResult, res, result.AddPostHook) diff --git a/execution/specExecutor_test.go b/execution/specExecutor_test.go index d09c62d21..3e1e46de2 100644 --- a/execution/specExecutor_test.go +++ b/execution/specExecutor_test.go @@ -258,7 +258,7 @@ func (r *mockRunner) IsMultithreaded() bool { } func (r *mockRunner) Info() *runner.RunnerInfo { - return &runner.RunnerInfo{Killed:false} + return &runner.RunnerInfo{Killed: false} } func (r *mockRunner) Pid() int { @@ -714,7 +714,6 @@ func TestExecuteShouldMarkSpecAsSkippedWhenAllScenariosSkipped(t *testing.T) { se := newSpecExecutor(exampleSpecWithScenarios, r, nil, errs, 0) se.scenarioExecutor = &mockExecutor{ executeFunc: func(i gauge.Item, r result.Result) { - r.(*result.ScenarioResult).ProtoScenario.Skipped = true r.(*result.ScenarioResult).ProtoScenario.ExecutionStatus = gauge_messages.ExecutionStatus_SKIPPED }, } diff --git a/execution/stepExecutor.go b/execution/stepExecutor.go index 4446d96e5..bd9d7b6fc 100644 --- a/execution/stepExecutor.go +++ b/execution/stepExecutor.go @@ -41,7 +41,6 @@ func (e *stepExecutor) executeStep(step *gauge.Step, protoStep *gauge_messages.P executeStepMessage := &gauge_messages.Message{MessageType: gauge_messages.Message_ExecuteStep, ExecuteStepRequest: stepRequest} stepExecutionStatus := e.runner.ExecuteAndGetStatus(executeStepMessage) stepExecutionStatus.Message = append(stepResult.ProtoStepExecResult().GetExecutionResult().Message, stepExecutionStatus.Message...) - stepExecutionStatus.Screenshots = append(stepResult.ProtoStepExecResult().GetExecutionResult().Screenshots, stepExecutionStatus.Screenshots...) if stepExecutionStatus.GetFailed() { e.currentExecutionInfo.CurrentStep.ErrorMessage = stepExecutionStatus.GetErrorMessage() e.currentExecutionInfo.CurrentStep.StackTrace = stepExecutionStatus.GetStackTrace() @@ -72,7 +71,6 @@ func (e *stepExecutor) notifyBeforeStepHook(stepResult *result.StepResult) { res := executeHook(m, stepResult, e.runner) stepResult.ProtoStep.PreHookMessages = res.Message stepResult.ProtoStep.PreHookScreenshotFiles = res.ScreenshotFiles - stepResult.ProtoStep.PreHookScreenshots = res.Screenshots if res.GetFailed() { setStepFailure(e.currentExecutionInfo) handleHookFailure(stepResult, res, result.AddPreHook) @@ -90,7 +88,6 @@ func (e *stepExecutor) notifyAfterStepHook(stepResult *result.StepResult) { res := executeHook(m, stepResult, e.runner) stepResult.ProtoStep.PostHookMessages = res.Message stepResult.ProtoStep.PostHookScreenshotFiles = res.ScreenshotFiles - stepResult.ProtoStep.PostHookScreenshots = res.Screenshots if res.GetFailed() { setStepFailure(e.currentExecutionInfo) handleHookFailure(stepResult, res, result.AddPostHook) diff --git a/plugin/plugin.go b/plugin/plugin.go index 07348a8fe..9288a8115 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -32,6 +32,7 @@ import ( "github.com/getgauge/gauge/version" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" ) @@ -252,7 +253,7 @@ func startGRPCPlugin(pd *PluginDescriptor, command []string) (*plugin, error) { } logger.Debugf(true, "Attempting to connect to grpc server at port: %s", port) gRPCConn, err := grpc.Dial(fmt.Sprintf("%s:%s", "127.0.0.1", port), - grpc.WithInsecure(), + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(1024*1024*1024), grpc.MaxCallRecvMsgSize(1024*1024*1024)), grpc.WithBlock()) if err != nil { diff --git a/refactor/refactor.go b/refactor/refactor.go index 1e14b50bb..7ab13bbab 100644 --- a/refactor/refactor.go +++ b/refactor/refactor.go @@ -103,11 +103,13 @@ func (refactoringResult *refactoringResult) WriteToDisk() { if !refactoringResult.Success { return } + // fileChange.FileContent need not be deprecated. To save the refactored file, it is much simpler and less error prone + // to replace the file with new content, rather than parsing again and replacing specific lines. for _, fileChange := range refactoringResult.SpecsChanged { - util.SaveFile(fileChange.FileName, fileChange.FileContent, true) + util.SaveFile(fileChange.FileName, fileChange.FileContent, true) //nolint:staticcheck } for _, fileChange := range refactoringResult.ConceptsChanged { - util.SaveFile(fileChange.FileName, fileChange.FileContent, true) + util.SaveFile(fileChange.FileName, fileChange.FileContent, true) //nolint:staticcheck } } diff --git a/runner/grpcRunner.go b/runner/grpcRunner.go index 667e294cd..6e2e310fc 100644 --- a/runner/grpcRunner.go +++ b/runner/grpcRunner.go @@ -23,6 +23,7 @@ import ( errdetails "google.golang.org/genproto/googleapis/rpc/errdetails" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" ) @@ -42,6 +43,7 @@ type GrpcRunner struct { IsExecuting bool } +//nolint:staticcheck func (r *GrpcRunner) invokeLegacyLSPService(message *gm.Message) (*gm.Message, error) { switch message.MessageType { case gm.Message_CacheFileRequest: @@ -326,7 +328,7 @@ func StartGrpcRunner(m *manifest.Manifest, stdout, stderr io.Writer, timeout tim } logger.Debugf(true, "Attempting to connect to grpc server at port: %s", port) conn, err := grpc.Dial(fmt.Sprintf("%s:%s", host, port), - grpc.WithInsecure(), + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(oneGB), grpc.MaxCallSendMsgSize(oneGB)), grpc.WithBlock()) logger.Debugf(true, "Successfully made the connection with runner with port: %s", port)