| 1 | package telemetry |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/release" |
| 8 | ) |
| 9 | |
| 10 | func TestResolveAppThenAccountThenDefault(t *testing.T) { |
| 11 | ctx := context.Background() |
| 12 | s := release.NewDirStore(t.TempDir()) |
| 13 | r, err := Resolve(ctx, s, "bab", "web") |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | if r.LogLevel != LogLevelError || r.LogLevelFrom != "default" || r.Count != CountOff || r.CountFrom != "default" || r.Door != DoorOn { |
| 18 | t.Fatalf("defaults = %+v", r) |
| 19 | } |
| 20 | if err := Update(ctx, s, AccountKey("bab"), func(st *Settings) { |
| 21 | st.Errors = &Errors{LogLevel: LogLevelWarn} |
| 22 | st.Analytics = &Analytics{Count: CountEdge} |
| 23 | }); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | r, _ = Resolve(ctx, s, "bab", "web") |
| 27 | if r.LogLevel != LogLevelWarn || r.LogLevelFrom != "account" || r.Count != CountEdge || r.CountFrom != "account" || r.Door != DoorOn || r.DoorFrom != "default" { |
| 28 | t.Fatalf("account level = %+v", r) |
| 29 | } |
| 30 | if err := Update(ctx, s, AppKey("bab", "web"), func(st *Settings) { |
| 31 | st.Analytics = &Analytics{Count: CountOff} |
| 32 | }); err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | r, _ = Resolve(ctx, s, "bab", "web") |
| 36 | if r.LogLevel != LogLevelWarn || r.Count != CountOff || r.CountFrom != "app" { |
| 37 | t.Fatalf("app override = %+v", r) |
| 38 | } |
| 39 | // Update preserves the other key. |
| 40 | if err := Update(ctx, s, AppKey("bab", "web"), func(st *Settings) { st.Errors = &Errors{LogLevel: LogLevelError} }); err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | got, _, _ := Read(ctx, s, AppKey("bab", "web")) |
| 44 | if got.Analytics == nil || got.Analytics.Count != CountOff || got.Errors == nil || got.Errors.LogLevel != LogLevelError { |
| 45 | t.Fatalf("read back = %+v", got) |
| 46 | } |
| 47 | } |
| 48 | |