Skip to content

Commit facbdac

Browse files
authored
Removed compilation step in main_test. (#198)
This speeds up the test slightly and is simpler.
1 parent 1e1cf73 commit facbdac

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

cmd/stackdriver-prometheus-sidecar/main_test.go

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ package main
1616
import (
1717
"bytes"
1818
"errors"
19-
"flag"
20-
"fmt"
2119
"net/http"
2220
"os"
2321
"os/exec"
24-
"path/filepath"
2522
"testing"
2623
"time"
2724

@@ -38,31 +35,12 @@ import (
3835
var promPath string
3936

4037
func TestMain(m *testing.M) {
41-
flag.Parse()
42-
if testing.Short() {
38+
if os.Getenv("RUN_MAIN") == "" {
39+
// Run the test directly.
4340
os.Exit(m.Run())
4441
}
45-
// On linux with a global proxy the tests will fail as the go client(http,grpc) tries to connect through the proxy.
46-
os.Setenv("no_proxy", "localhost,127.0.0.1,0.0.0.0,:")
47-
48-
var err error
49-
promPath, err = os.Getwd()
50-
if err != nil {
51-
fmt.Printf("can't get current dir :%s \n", err)
52-
os.Exit(1)
53-
}
54-
promPath = filepath.Join(promPath, "prometheus")
55-
56-
build := exec.Command("go", "build", "-o", promPath)
57-
output, err := build.CombinedOutput()
58-
if err != nil {
59-
fmt.Printf("compilation error :%s \n", output)
60-
os.Exit(1)
61-
}
6242

63-
exitCode := m.Run()
64-
os.Remove(promPath)
65-
os.Exit(exitCode)
43+
main()
6644
}
6745

6846
// As soon as prometheus starts responding to http request should be able to accept Interrupt signals for a gracefull shutdown.
@@ -71,7 +49,8 @@ func TestStartupInterrupt(t *testing.T) {
7149
t.Skip("skipping test in short mode.")
7250
}
7351

74-
prom := exec.Command(promPath, "--stackdriver.project-id=1234", "--prometheus.wal-directory=testdata/wal")
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")
7554
var bout, berr bytes.Buffer
7655
prom.Stdout = &bout
7756
prom.Stderr = &berr

0 commit comments

Comments
 (0)