diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2024-02-23 15:01:41 +0200 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2024-02-23 15:01:41 +0200 |
| commit | a3e10757a52fa47a0608afd88986162ca5eb22cc (patch) | |
| tree | dce61c6695bc3badd455a64767252e6947b32711 /integrationtests | |
| parent | 85780654df870dc4170b93a8ed5a5dbfa917fe5d (diff) | |
lint warnings
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/commandutils.go | 16 | ||||
| -rw-r--r-- | integrationtests/dserver_test.go | 4 | ||||
| -rw-r--r-- | integrationtests/dtail_test.go | 8 | ||||
| -rw-r--r-- | integrationtests/dtailhealth_test.go | 2 | ||||
| -rw-r--r-- | integrationtests/fileutils.go | 11 |
5 files changed, 19 insertions, 22 deletions
diff --git a/integrationtests/commandutils.go b/integrationtests/commandutils.go index 959288a..8d81955 100644 --- a/integrationtests/commandutils.go +++ b/integrationtests/commandutils.go @@ -17,7 +17,7 @@ func runCommand(ctx context.Context, t *testing.T, stdoutFile, cmdStr string, args ...string) (int, error) { if _, err := os.Stat(cmdStr); err != nil { - return 0, fmt.Errorf("no such executable '%s', please compile first: %v", cmdStr, err) + return 0, fmt.Errorf("no such executable '%s', please compile first: %w", cmdStr, err) } t.Log("Creating stdout file", stdoutFile) @@ -31,7 +31,7 @@ func runCommand(ctx context.Context, t *testing.T, stdoutFile, cmdStr string, cmd := exec.CommandContext(ctx, cmdStr, args...) out, err := cmd.CombinedOutput() t.Log("Done running command!", err) - fd.Write(out) + _, _ = fd.Write(out) return exitCodeFromError(err), err } @@ -56,7 +56,7 @@ func startCommand(ctx context.Context, t *testing.T, inPipeFile, if _, err := os.Stat(cmdStr); err != nil { return stdoutCh, stderrCh, nil, - fmt.Errorf("no such executable '%s', please compile first: %v", cmdStr, err) + fmt.Errorf("no such executable '%s', please compile first: %w", cmdStr, err) } t.Log(cmdStr, strings.Join(args, " ")) @@ -85,13 +85,13 @@ func startCommand(ctx context.Context, t *testing.T, inPipeFile, // Read input file and send to stdin pipe? if inPipeFile != "" { - t.Log(fmt.Sprintf("Piping %s to stdin pipe", inPipeFile)) + t.Logf("Piping %s to stdin pipe", inPipeFile) fd, err := os.Open(inPipeFile) if err != nil { return stdoutCh, stderrCh, nil, err } go func() { - io.Copy(stdinPipe, bufio.NewReader(fd)) + _, _ = io.Copy(stdinPipe, bufio.NewReader(fd)) stdinPipe.Close() fd.Close() }() @@ -135,8 +135,8 @@ func waitForCommand(ctx context.Context, t *testing.T, t.Log(line) } case cmdErr := <-cmdErrCh: - t.Log(fmt.Sprintf("Command finished with with exit code %d: %v", - exitCodeFromError(cmdErr), cmdErr)) + t.Logf("Command finished with with exit code %d: %v", + exitCodeFromError(cmdErr), cmdErr) return } } @@ -150,5 +150,5 @@ func exitCodeFromError(err error) int { ws := exitError.Sys().(syscall.WaitStatus) return ws.ExitStatus() } - panic(fmt.Sprintf("Unable to get process exit code from error: %v", err)) + panic(fmt.Errorf("Unable to get process exit code from error: %w", err)) } diff --git a/integrationtests/dserver_test.go b/integrationtests/dserver_test.go index 5b8a091..eaca23b 100644 --- a/integrationtests/dserver_test.go +++ b/integrationtests/dserver_test.go @@ -89,8 +89,8 @@ func TestDServer2(t *testing.T) { parts := []string{"INFO", "19801011-424242", "1", "dserver_test.go", "1", "1", "1", "1.0", "1m", "MAPREDUCE:INTEGRATIONTEST", "foo=1", "bar=42"} - fd.WriteString(strings.Join(parts, "|")) - fd.WriteString("\n") + _, _ = fd.WriteString(strings.Join(parts, "|")) + _, _ = fd.WriteString("\n") case <-ctx.Done(): return } diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go index 64a32f1..752dafb 100644 --- a/integrationtests/dtail_test.go +++ b/integrationtests/dtail_test.go @@ -75,8 +75,8 @@ func TestDTailWithServer(t *testing.T) { for { select { case <-time.After(time.Second): - fd.WriteString(time.Now().String()) - fd.WriteString(fmt.Sprintf(" - Hello %s\n", greetings[circular])) + _, _ = fd.WriteString(time.Now().String()) + _, _ = fd.WriteString(fmt.Sprintf(" - Hello %s\n", greetings[circular])) circular = (circular + 1) % len(greetings) case <-ctx.Done(): return @@ -120,8 +120,8 @@ func TestDTailWithServer(t *testing.T) { for i, g := range greetingsRecv { index := (i + offset) % len(greetings) if greetings[index] != g { - t.Error(fmt.Sprintf("Expected '%s' but got '%s' at '%v' vs '%v'\n", - g, greetings[index], greetings, greetingsRecv)) + t.Errorf("Expected '%s' but got '%s' at '%v' vs '%v'\n", + g, greetings[index], greetings, greetingsRecv) return } } diff --git a/integrationtests/dtailhealth_test.go b/integrationtests/dtailhealth_test.go index 49fbd38..7946824 100644 --- a/integrationtests/dtailhealth_test.go +++ b/integrationtests/dtailhealth_test.go @@ -20,7 +20,7 @@ func TestDTailHealth1(t *testing.T) { t.Log("Serverless check, is supposed to exit with warning state.") exitCode, err := runCommand(context.TODO(), t, outFile, "../dtailhealth") if exitCode != 1 { - t.Error(fmt.Sprintf("Expected exit code '1' but got '%d': %v", exitCode, err)) + t.Errorf("Expected exit code '1' but got '%d': %v", exitCode, err) return } diff --git a/integrationtests/fileutils.go b/integrationtests/fileutils.go index d13617d..a1e1051 100644 --- a/integrationtests/fileutils.go +++ b/integrationtests/fileutils.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "encoding/base64" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -25,7 +24,7 @@ func mapFile(t *testing.T, file string) (map[string]int, error) { scanner.Split(bufio.ScanLines) for scanner.Scan() { line := scanner.Text() - count, _ := contents[line] + count := contents[line] contents[line] = count + 1 } @@ -59,13 +58,11 @@ func compareFilesContents(t *testing.T, fileA, fileB string) error { } // The mapreduce result can be in a different order each time (Golang maps are not sorted). - t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)", - fileA, fileB)) + t.Logf("Checking whether %s has same lines as file %s (ignoring line order)", fileA, fileB) if err := compareMaps(a, b); err != nil { return err } - t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)", - fileB, fileA)) + t.Logf("Checking whether %s has same lines as file %s (ignoring line order)", fileB, fileA) if err := compareMaps(b, a); err != nil { return err } @@ -108,7 +105,7 @@ func fileContainsStr(t *testing.T, file, str string) error { } func shaOfFile(t *testing.T, file string) string { - bytes, err := ioutil.ReadFile(file) + bytes, err := os.ReadFile(file) if err != nil { t.Error(err) } |
