Skip to content

Commit

Permalink
Fix integTest target by honoring TEST_ENVIRONMENT (#9737) (#9741)
Browse files Browse the repository at this point in the history
This backports a small portion of #9724.

(cherry picked from commit 6ee32d2)
  • Loading branch information
andrewkroh authored Dec 21, 2018
1 parent 3a3d2f5 commit c6e1ee5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions dev-tools/mage/integtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ package mage
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -96,6 +98,10 @@ func StopIntegTestEnv() error {
return nil
}

if _, skip := skipIntegTest(); skip {
return nil
}

composeEnv, err := integTestDockerComposeEnvVars()
if err != nil {
return err
Expand Down Expand Up @@ -130,6 +136,11 @@ func StopIntegTestEnv() error {
//
// Always use this with AddIntegTestUsage() and defer StopIntegTestEnv().
func RunIntegTest(mageTarget string, test func() error, passThroughEnvVars ...string) error {
if reason, skip := skipIntegTest(); skip {
fmt.Printf(">> %v: Skipping because %v\n", mageTarget, reason)
return nil
}

AddIntegTestUsage()
defer StopIntegTestEnv()

Expand Down Expand Up @@ -232,6 +243,31 @@ func haveIntegTestEnvRequirements() error {
return nil
}

// skipIntegTest returns true if integ tests should be skipped.
func skipIntegTest() (reason string, skip bool) {
if IsInIntegTestEnv() {
return "", false
}

// Honor the TEST_ENVIRONMENT value if set.
if testEnvVar, isSet := os.LookupEnv("TEST_ENVIRONMENT"); isSet {
enabled, err := strconv.ParseBool(testEnvVar)
if err != nil {
panic(errors.Wrap(err, "failed to parse TEST_ENVIRONMENT value"))
}
return "TEST_ENVIRONMENT=" + testEnvVar, !enabled
}

// Otherwise skip if we don't have all the right dependencies.
if err := haveIntegTestEnvRequirements(); err != nil {
// Skip if we don't meet the requirements.
log.Println("Skipping integ test because:", err)
return "docker is not available", true
}

return "", false
}

// integTestDockerComposeEnvVars returns the environment variables used for
// executing docker-compose (not the variables passed into the containers).
// docker-compose uses these when evaluating docker-compose.yml files.
Expand Down

0 comments on commit c6e1ee5

Please sign in to comment.