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 "bytes"
5 "strings"
6 "testing"
7)
8
9// printStoreStatus must name an app's environment stores BEFORE it gives up
10// with "not declared". An app whose storage is entirely per-environment has
11// no store of its own, so stopping at the not-declared line would report that
12// it has no storage while it owns a bucket per environment.
13func TestPrintStoreStatusNamesEnvironmentsWithNoAppStore(t *testing.T) {
14 var buf bytes.Buffer
15 printStoreStatus(&buf, apiStoreReply{
16 App: "managed",
17 Backend: "aws",
18 Environments: []string{"acme", "globex"},
19 })
20 out := buf.String()
21 for _, want := range []string{
22 "environments with their own store: acme, globex",
23 "carlos store status --app managed --environment acme",
24 "not declared", // still true of the app's OWN store
25 } {
26 if !strings.Contains(out, want) {
27 t.Fatalf("status is missing %q:\n%s", want, out)
28 }
29 }
30}
31
32// ...and exactly once for an app that has both its own store and environment
33// stores — the line was inline before it was extracted, and printing it from
34// two places is the obvious way to get it twice.
35func TestPrintStoreStatusNamesEnvironmentsOnce(t *testing.T) {
36 var buf bytes.Buffer
37 printStoreStatus(&buf, apiStoreReply{
38 App: "both",
39 Backend: "aws",
40 Declared: &apiStoreDeclared{EnvPrefix: "CARLOS_STORE"},
41 Environments: []string{"acme"},
42 })
43 if n := strings.Count(buf.String(), "environments with their own store"); n != 1 {
44 t.Fatalf("the environments line appears %d times, want 1:\n%s", n, buf.String())
45 }
46}
47