(m *testing.M)
| 66 | ) |
| 67 | |
| 68 | func TestMain(m *testing.M) { |
| 69 | testcommon.ClearDockerEnv() |
| 70 | DdevBin = testsetup.MustResolveDdevBinary() |
| 71 | |
| 72 | bash := util.FindBashPath() |
| 73 | ver, _ := exec.RunCommand(bash, []string{"-c", fmt.Sprintf("%s --version -j | jq -r .raw.version", DdevBin)}) |
| 74 | ver = strings.TrimSpace(ver) |
| 75 | output.UserOut.Printf("Running DDEV with ddev=%s (%s)\n", DdevBin, ver) |
| 76 | |
| 77 | err := os.Setenv("DDEV_NONINTERACTIVE", "true") |
| 78 | if err != nil { |
| 79 | output.UserErr.Errorln("could not set noninteractive mode, failed to Setenv, err: ", err) |
| 80 | } |
| 81 | |
| 82 | // We don't want the tests reporting telemetry. |
| 83 | _ = os.Setenv("DDEV_NO_INSTRUMENTATION", "true") |
| 84 | _ = os.Setenv("MUTAGEN_DATA_DIRECTORY", globalconfig.GetMutagenDataDirectory()) |
| 85 | |
| 86 | // If GOTEST_SHORT is an integer, then use it as index for a single usage |
| 87 | // in the array. Any value can be used, it will default to using the |
| 88 | // first site in the array. |
| 89 | gotestShort := os.Getenv("GOTEST_SHORT") |
| 90 | if gotestShort != "" { |
| 91 | useSite := 0 |
| 92 | if site, err := strconv.Atoi(gotestShort); err == nil && site >= 0 && site < len(TestSites) { |
| 93 | useSite = site |
| 94 | } |
| 95 | TestSites = []testcommon.TestSite{TestSites[useSite]} |
| 96 | } |
| 97 | |
| 98 | output.UserOut.Debugln("Preparing TestSites") |
| 99 | for i := range TestSites { |
| 100 | oldProject := globalconfig.GetProject(TestSites[i].Name) |
| 101 | if oldProject != nil { |
| 102 | out, err := osexec.Command(DdevBin, "stop", "-RO", TestSites[i].Name).CombinedOutput() |
| 103 | if err != nil { |
| 104 | output.UserErr.Fatalf("ddev stop -RO on %s failed: %v, output=%s", TestSites[i].Name, err, out) |
| 105 | } |
| 106 | } |
| 107 | if err = globalconfig.ReadGlobalConfig(); err != nil { |
| 108 | output.UserErr.Fatalf("Failed to read global config: %v", err) |
| 109 | } |
| 110 | |
| 111 | output.UserOut.Debugf("Preparing %s", TestSites[i].Name) |
| 112 | err = TestSites[i].Prepare() |
| 113 | if err != nil { |
| 114 | output.UserErr.Fatalf("Prepare() failed in TestMain site=%s, err=%v\n", TestSites[i].Name, err) |
| 115 | } |
| 116 | } |
| 117 | output.UserOut.Debugln("Adding TestSites") |
| 118 | err = addSites() |
| 119 | if err != nil { |
| 120 | removeSites() |
| 121 | util.Failed("addSites() failed: %v", err) |
| 122 | } |
| 123 | |
| 124 | output.UserOut.Debugln("Running tests.") |
| 125 | testRun := m.Run() |
nothing calls this directly
no test coverage detected