Skip to content

Commit

Permalink
stop shadowing vars; prefer explicit over clever in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Jul 27, 2024
1 parent c34cc88 commit d89fe9f
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/bpm/integration2/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,45 @@ func TestRun(t *testing.T) {
defer s.Cleanup()

s.LoadFixture("errand", "testdata/errand.yml")
stdoutSentinel := "stdout"
stderrSentinel := "stderr"

cmd := s.BPMCmd("run", "errand")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("failed to run bpm: %s", output)
}

if contents, sentinel := string(output), "stdout"; !strings.Contains(contents, sentinel) {
t.Errorf("stdout/stderr did not contain %q, contents: %q", sentinel, contents)
combinedOutput := string(output)
if !strings.Contains(combinedOutput, stdoutSentinel) {
t.Errorf("stdout/stderr did not contain %q, contents: %q", stdoutSentinel, combinedOutput)
}
if contents, sentinel := string(output), "stderr"; !strings.Contains(contents, sentinel) {
t.Errorf("stdout/stderr did not contain %q, contents: %q", sentinel, contents)
if !strings.Contains(combinedOutput, stderrSentinel) {
t.Errorf("stdout/stderr did not contain %q, contents: %q", stderrSentinel, combinedOutput)
}

stdout, err := os.ReadFile(s.Path("sys", "log", "errand", "errand.stdout.log"))
if err != nil {
t.Fatalf("failed to read stdout log: %v", err)
}
if contents, sentinel := string(stdout), "stdout"; !strings.Contains(contents, sentinel) {
t.Errorf("stdout log file did not contain %q, contents: %q", sentinel, contents)

stdoutLog := string(stdout)
if !strings.Contains(stdoutLog, stdoutSentinel) {
t.Errorf("stdout log file did not contain %q, stdoutLog: %q", stdoutSentinel, stdoutLog)
}

stderr, err := os.ReadFile(s.Path("sys", "log", "errand", "errand.stderr.log"))
if err != nil {
t.Fatalf("failed to read stderr log: %v", err)
}
if contents, sentinel := string(stderr), "stderr"; !strings.Contains(contents, sentinel) {
t.Errorf("stderr log file did not contain %q, contents: %q", sentinel, contents)
stderrLog := string(stderr)
if !strings.Contains(stderrLog, stderrSentinel) {
t.Errorf("stderr log file did not contain %q, contents: %q", stderrSentinel, stderrLog)
}

pidfile := s.Path("sys", "run", "bpm", "errand", "errand.pid")
if _, err := os.Stat(pidfile); !os.IsNotExist(err) {
_, err = os.Stat(pidfile)
if !os.IsNotExist(err) {
t.Errorf("expected %q not to exist but it did", pidfile)
}
}
Expand All @@ -115,7 +122,9 @@ func TestRunWithEnvFlags(t *testing.T) {
if err != nil {
t.Fatalf("failed to run bpm: %s", output)
}
if contents, sentinel := string(output), sentinel; !strings.Contains(contents, sentinel) {

contents := string(output)
if !strings.Contains(contents, sentinel) {
t.Errorf("output did not contain %q; contents: %q", sentinel, contents)
}
}
Expand Down Expand Up @@ -167,7 +176,10 @@ func TestRunWithVolumeFlags(t *testing.T) {
if err != nil {
t.Fatalf("failed to read extra volume file: %v", err)
}
if contents, sentinel := string(fileContents), "success"; !strings.Contains(contents, sentinel) {

sentinel := "success"
contents := string(fileContents)
if !strings.Contains(contents, sentinel) {
t.Errorf("extra volume file did not contain %q, contents: %q", sentinel, contents)
}
}
Expand Down

0 comments on commit d89fe9f

Please sign in to comment.