Skip to content

Commit

Permalink
Removed compilation step in main_test. (#198)
Browse files Browse the repository at this point in the history
This speeds up the test slightly and is simpler.
  • Loading branch information
jkohen authored Nov 27, 2019
1 parent 1e1cf73 commit facbdac
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions cmd/stackdriver-prometheus-sidecar/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ package main
import (
"bytes"
"errors"
"flag"
"fmt"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"

Expand All @@ -38,31 +35,12 @@ import (
var promPath string

func TestMain(m *testing.M) {
flag.Parse()
if testing.Short() {
if os.Getenv("RUN_MAIN") == "" {
// Run the test directly.
os.Exit(m.Run())
}
// On linux with a global proxy the tests will fail as the go client(http,grpc) tries to connect through the proxy.
os.Setenv("no_proxy", "localhost,127.0.0.1,0.0.0.0,:")

var err error
promPath, err = os.Getwd()
if err != nil {
fmt.Printf("can't get current dir :%s \n", err)
os.Exit(1)
}
promPath = filepath.Join(promPath, "prometheus")

build := exec.Command("go", "build", "-o", promPath)
output, err := build.CombinedOutput()
if err != nil {
fmt.Printf("compilation error :%s \n", output)
os.Exit(1)
}

exitCode := m.Run()
os.Remove(promPath)
os.Exit(exitCode)
main()
}

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

prom := exec.Command(promPath, "--stackdriver.project-id=1234", "--prometheus.wal-directory=testdata/wal")
prom := exec.Command(os.Args[0], "--stackdriver.project-id=1234", "--prometheus.wal-directory=testdata/wal")
prom.Env = append(os.Environ(), "RUN_MAIN=1")
var bout, berr bytes.Buffer
prom.Stdout = &bout
prom.Stderr = &berr
Expand Down

0 comments on commit facbdac

Please sign in to comment.