package inventory import ( "encoding/json" "os" "strings" "testing" ) // **The store the tests run is the store the mesh runs** (novox/hq ADR 0227 rule 9, ADR 0237). In a merge // check the build seat raises the store of the major release the facts snapshot says the mesh's store // runs; this holds the two equal there, so a test passing here is a test passing on that release. Without // a snapshot — on a workstation — it says what it ran against and compares nothing. func TestTheStoreTheTestsRunIsTheStoreTheMeshRuns(t *testing.T) { inv := ForTest(t) ran, err := inv.ServerVersionForTest(t) if err != nil { t.Fatal(err) } path := os.Getenv("MESH_FACTS") if path == "" { t.Logf("the tests ran the store at %s; with no MESH_FACTS, nothing to compare it with", ran) return } body, err := os.ReadFile(path) if err != nil { t.Fatal(err) } var f struct { Versions struct { Store string `json:"store"` } `json:"versions"` } if err := json.Unmarshal(body, &f); err != nil { t.Fatal(err) } major := func(v string) string { m, _, _ := strings.Cut(strings.TrimSpace(v), "."); return m } if f.Versions.Store != "" && major(ran) != major(f.Versions.Store) { t.Errorf("the tests ran the store at %s and the mesh's store runs %s", ran, f.Versions.Store) } } // ServerVersionForTest is the store's own word for its release. func (i *Inventory) ServerVersionForTest(t *testing.T) (string, error) { t.Helper() var v string err := i.store.Pool().QueryRow(t.Context(), `show server_version`).Scan(&v) return v, err }