package telemetry import ( "context" "testing" "github.com/carlosframework/platform/internal/release" ) func TestResolveAppThenAccountThenDefault(t *testing.T) { ctx := context.Background() s := release.NewDirStore(t.TempDir()) r, err := Resolve(ctx, s, "bab", "web") if err != nil { t.Fatal(err) } if r.LogLevel != LogLevelError || r.LogLevelFrom != "default" || r.Count != CountOff || r.CountFrom != "default" || r.Door != DoorOn { t.Fatalf("defaults = %+v", r) } if err := Update(ctx, s, AccountKey("bab"), func(st *Settings) { st.Errors = &Errors{LogLevel: LogLevelWarn} st.Analytics = &Analytics{Count: CountEdge} }); err != nil { t.Fatal(err) } r, _ = Resolve(ctx, s, "bab", "web") if r.LogLevel != LogLevelWarn || r.LogLevelFrom != "account" || r.Count != CountEdge || r.CountFrom != "account" || r.Door != DoorOn || r.DoorFrom != "default" { t.Fatalf("account level = %+v", r) } if err := Update(ctx, s, AppKey("bab", "web"), func(st *Settings) { st.Analytics = &Analytics{Count: CountOff} }); err != nil { t.Fatal(err) } r, _ = Resolve(ctx, s, "bab", "web") if r.LogLevel != LogLevelWarn || r.Count != CountOff || r.CountFrom != "app" { t.Fatalf("app override = %+v", r) } // Update preserves the other key. if err := Update(ctx, s, AppKey("bab", "web"), func(st *Settings) { st.Errors = &Errors{LogLevel: LogLevelError} }); err != nil { t.Fatal(err) } got, _, _ := Read(ctx, s, AppKey("bab", "web")) if got.Analytics == nil || got.Analytics.Count != CountOff || got.Errors == nil || got.Errors.LogLevel != LogLevelError { t.Fatalf("read back = %+v", got) } }