Skip to content

Commit d33842c

Browse files
committed
chore(test): add backwards-compatibility tests for region warning
1 parent f8673e0 commit d33842c

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

cmd/lk/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ func resolveRegion(cmd *cli.Command, settingsMap map[string]string, title string
19671967
for _, r := range regionOptions {
19681968
label := r
19691969
if slices.Contains(warnRegions, r) {
1970-
label = r + " " + util.Dimmed("⚠︎ GDPR compliance required")
1970+
label = r + " " + util.Warn("⚠︎ GDPR compliance required")
19711971
}
19721972
options = append(options, huh.NewOption(label, r))
19731973
}

cmd/lk/agent_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,3 +602,31 @@ func TestResolveAttributes(t *testing.T) {
602602
})
603603
}
604604
}
605+
606+
// An older server sends neither residency_warning_regions nor project_data_region.
607+
// The advisory must then be inert rather than erroring or prompting, so a new CLI
608+
// keeps working against a server that predates it.
609+
func TestConfirmRegionResidencyWithoutServerSettings(t *testing.T) {
610+
settingsMap := map[string]string{"available_regions": "us-east,eu-central"}
611+
warnRegions := splitSetting(settingsMap["residency_warning_regions"])
612+
require.Empty(t, warnRegions)
613+
614+
err := confirmRegionResidency(&cli.Command{}, "eu-central",
615+
settingsMap["project_data_region"], warnRegions)
616+
require.NoError(t, err)
617+
}
618+
619+
// An EU project gets the param with an empty value; it must behave like absent.
620+
func TestConfirmRegionResidencyWithEmptyWarningRegions(t *testing.T) {
621+
warnRegions := splitSetting("")
622+
require.Empty(t, warnRegions)
623+
require.NoError(t, confirmRegionResidency(&cli.Command{}, "eu-central", "eu", warnRegions))
624+
}
625+
626+
// A flagged region without a TTY (or with --yes) warns and proceeds rather than
627+
// blocking, so existing automation deploying into the EU keeps working.
628+
func TestConfirmRegionResidencyProceedsWhenPromptsSkipped(t *testing.T) {
629+
warnRegions := splitSetting("eu-central")
630+
require.Equal(t, []string{"eu-central"}, warnRegions)
631+
require.NoError(t, confirmRegionResidency(&cli.Command{}, "eu-central", "us", warnRegions))
632+
}

pkg/util/theme.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ func Dimmed(text string) string {
177177
return Theme.Focused.Description.Render(text)
178178
}
179179

180+
// Warn renders text in the active theme's Warning style
181+
func Warn(text string) string {
182+
return lipgloss.NewStyle().Foreground(activePalette.Warning).Render(text)
183+
}
184+
185+
// Warn renders text in the active theme's Error style
186+
func Err(text string) string {
187+
return lipgloss.NewStyle().Foreground(activePalette.Error).Render(text)
188+
}
189+
180190
// Hyperlink wraps label in an OSC 8 terminal hyperlink pointing at url. Terminals
181191
// that support OSC 8 render label as a clickable link; others ignore the escape
182192
// and show label unchanged. Gate calls on an interactive terminal (see

0 commit comments

Comments
 (0)