package main import ( "bytes" "strings" "testing" ) // printStoreStatus must name an app's environment stores BEFORE it gives up // with "not declared". An app whose storage is entirely per-environment has // no store of its own, so stopping at the not-declared line would report that // it has no storage while it owns a bucket per environment. func TestPrintStoreStatusNamesEnvironmentsWithNoAppStore(t *testing.T) { var buf bytes.Buffer printStoreStatus(&buf, apiStoreReply{ App: "managed", Backend: "aws", Environments: []string{"acme", "globex"}, }) out := buf.String() for _, want := range []string{ "environments with their own store: acme, globex", "carlos store status --app managed --environment acme", "not declared", // still true of the app's OWN store } { if !strings.Contains(out, want) { t.Fatalf("status is missing %q:\n%s", want, out) } } } // ...and exactly once for an app that has both its own store and environment // stores — the line was inline before it was extracted, and printing it from // two places is the obvious way to get it twice. func TestPrintStoreStatusNamesEnvironmentsOnce(t *testing.T) { var buf bytes.Buffer printStoreStatus(&buf, apiStoreReply{ App: "both", Backend: "aws", Declared: &apiStoreDeclared{EnvPrefix: "CARLOS_STORE"}, Environments: []string{"acme"}, }) if n := strings.Count(buf.String(), "environments with their own store"); n != 1 { t.Fatalf("the environments line appears %d times, want 1:\n%s", n, buf.String()) } }