carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestLoadPlanCatalogEnv(t *testing.T) {
10 t.Setenv("CARLOS_PLAN_CATALOG", "")
11 if c, err := planCatalog(); c != nil || err != nil {
12 t.Fatalf("unset: %v, %v", c, err)
13 }
14 t.Setenv("CARLOS_PLAN_CATALOG", "../../internal/plans/testdata/example-catalog.json")
15 if c, err := planCatalog(); c == nil || err != nil {
16 t.Fatalf("example: %v, %v", c, err)
17 }
18 bad := filepath.Join(t.TempDir(), "bad.json")
19 if err := os.WriteFile(bad, []byte(`{"version": ""}`), 0o600); err != nil {
20 t.Fatal(err)
21 }
22 for _, p := range []string{bad, filepath.Join(t.TempDir(), "missing.json")} {
23 t.Setenv("CARLOS_PLAN_CATALOG", p)
24 if c, err := planCatalog(); c != nil || err == nil {
25 t.Fatalf("%s: %v, %v; want an error", p, c, err)
26 }
27 }
28}
29