Download this file
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "os" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/rastrillo/rastrillo/budget" |
| 10 | |
| 11 | "amadan.net/oficina/base/internal/config" |
| 12 | ) |
| 13 | |
| 14 | func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |
| 15 | |
| 16 | // The printed value must be exactly what config.Load accepts. |
| 17 | func TestKeyRoundTripsThroughConfig(t *testing.T) { |
| 18 | var out bytes.Buffer |
| 19 | if err := run(&out); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | key := strings.TrimSpace(out.String()) |
| 23 | env := map[string]string{ |
| 24 | "BASE_ORIGIN": "https://base.example.com", "BASE_OWNER": "o@example.com", |
| 25 | "BASE_ASSERTION_KEY": key, |
| 26 | } |
| 27 | cfg, err := config.Load(func(k string) string { return env[k] }) |
| 28 | if err != nil { |
| 29 | t.Fatalf("config.Load rejected the printed key: %v", err) |
| 30 | } |
| 31 | if cfg.AssertionKey == nil { |
| 32 | t.Fatal("config.Load left AssertionKey nil") |
| 33 | } |
| 34 | var again bytes.Buffer |
| 35 | if err := run(&again); err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | if again.String() == out.String() { |
| 39 | t.Fatal("two runs printed the same key") |
| 40 | } |
| 41 | } |
| 42 | |