package main import ( "bytes" "os" "strings" "testing" "amadan.net/rastrillo/rastrillo/budget" "amadan.net/oficina/base/internal/config" ) func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } // The printed value must be exactly what config.Load accepts. func TestKeyRoundTripsThroughConfig(t *testing.T) { var out bytes.Buffer if err := run(&out); err != nil { t.Fatal(err) } key := strings.TrimSpace(out.String()) env := map[string]string{ "BASE_ORIGIN": "https://base.example.com", "BASE_OWNER": "o@example.com", "BASE_ASSERTION_KEY": key, } cfg, err := config.Load(func(k string) string { return env[k] }) if err != nil { t.Fatalf("config.Load rejected the printed key: %v", err) } if cfg.AssertionKey == nil { t.Fatal("config.Load left AssertionKey nil") } var again bytes.Buffer if err := run(&again); err != nil { t.Fatal(err) } if again.String() == out.String() { t.Fatal("two runs printed the same key") } }