fix(server): TestMain must not exit(0) before m.Run(); skip DB test individually
This commit is contained in:
@@ -8,17 +8,21 @@ import (
|
||||
"github.com/mrhid6/vantage/server/internal/models"
|
||||
)
|
||||
|
||||
var mongoAvailable bool
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
uri := os.Getenv("VANTAGE_TEST_MONGO_URI")
|
||||
if uri == "" {
|
||||
uri = "mongodb://localhost:27117"
|
||||
}
|
||||
if err := db.Connect(uri, "vantage_test"); err != nil {
|
||||
// No MongoDB available in this environment; skip DB-backed tests.
|
||||
os.Exit(0)
|
||||
// No MongoDB available in this environment; DB-backed tests will be skipped
|
||||
// individually, but the rest of the package's tests must still run.
|
||||
mongoAvailable = false
|
||||
} else {
|
||||
mongoAvailable = true
|
||||
}
|
||||
code := m.Run()
|
||||
os.Exit(code)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func mkUsageStep(name string) models.WorkflowStep {
|
||||
@@ -30,6 +34,9 @@ func mkWorkflowWithStep(name, stepID string) models.Workflow {
|
||||
}
|
||||
|
||||
func TestStepUsageCounts(t *testing.T) {
|
||||
if !mongoAvailable {
|
||||
t.Skip("mongo unavailable: set VANTAGE_TEST_MONGO_URI")
|
||||
}
|
||||
// A step used by two workflows, a step used by none.
|
||||
used, err := CreateStep(mkUsageStep("used-step"))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user