Skip to content

Commit db19050

Browse files
authored
Make main_test.go more precise and clear. (#202)
- Remove unused variable promPath. - Update variable name from "prom" to "cmd", as in the Prometheus community, "prom" means Prometheus, but we are testing stackdriver-proemtheus-sidecar. - Correct error messages.
1 parent facbdac commit db19050

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

cmd/stackdriver-prometheus-sidecar/main_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
metric_pb "google.golang.org/genproto/googleapis/api/metric"
3333
)
3434

35-
var promPath string
36-
3735
func TestMain(m *testing.M) {
3836
if os.Getenv("RUN_MAIN") == "" {
3937
// Run the test directly.
@@ -49,20 +47,20 @@ func TestStartupInterrupt(t *testing.T) {
4947
t.Skip("skipping test in short mode.")
5048
}
5149

52-
prom := exec.Command(os.Args[0], "--stackdriver.project-id=1234", "--prometheus.wal-directory=testdata/wal")
53-
prom.Env = append(os.Environ(), "RUN_MAIN=1")
50+
cmd := exec.Command(os.Args[0], "--stackdriver.project-id=1234", "--prometheus.wal-directory=testdata/wal")
51+
cmd.Env = append(os.Environ(), "RUN_MAIN=1")
5452
var bout, berr bytes.Buffer
55-
prom.Stdout = &bout
56-
prom.Stderr = &berr
57-
err := prom.Start()
53+
cmd.Stdout = &bout
54+
cmd.Stderr = &berr
55+
err := cmd.Start()
5856
if err != nil {
5957
t.Errorf("execution error: %v", err)
6058
return
6159
}
6260

6361
done := make(chan error)
6462
go func() {
65-
done <- prom.Wait()
63+
done <- cmd.Wait()
6664
}()
6765

6866
var startedOk bool
@@ -73,7 +71,7 @@ Loop:
7371
// error=nil means the sidecar has started so can send the interrupt signal and wait for the grace shutdown.
7472
if _, err := http.Get("http://localhost:9091/metrics"); err == nil {
7573
startedOk = true
76-
prom.Process.Signal(os.Interrupt)
74+
cmd.Process.Signal(os.Interrupt)
7775
select {
7876
case stoppedErr = <-done:
7977
break Loop
@@ -93,13 +91,13 @@ Loop:
9391
t.Logf("stodut: %v\n", bout.String())
9492
t.Logf("stderr: %v\n", berr.String())
9593
if !startedOk {
96-
t.Errorf("prometheus didn't start in the specified timeout")
94+
t.Errorf("prometheus-stackdriver-sidecar didn't start in the specified timeout")
9795
return
9896
}
99-
if err := prom.Process.Kill(); err == nil {
100-
t.Errorf("prometheus didn't shutdown gracefully after sending the Interrupt signal")
97+
if err := cmd.Process.Kill(); err == nil {
98+
t.Errorf("prometheus-stackdriver-sidecar didn't shutdown gracefully after sending the Interrupt signal")
10199
} else if stoppedErr != nil && stoppedErr.Error() != "signal: interrupt" { // TODO - find a better way to detect when the process didn't exit as expected!
102-
t.Errorf("prometheus exited with an unexpected error:%v", stoppedErr)
100+
t.Errorf("prometheus-stackdriver-sidecar exited with an unexpected error:%v", stoppedErr)
103101
}
104102
}
105103

0 commit comments

Comments
 (0)