package catalogue import ( "encoding/json" "strings" "testing" ) // A takes-config entry may lay a value under the name the file's software reads (issue 751): the key stays a // config key, lower-case, and the file names its own variable, such as ATLASSIAN_URL. // renaming is inConfigForm with its rules file taking `url` as NOTIFIER_URL, a value the code reading the file // falls back on when the file lacks it. func renaming() map[string]any { m := inConfigForm() m["config"].(map[string]any)["url"] = map[string]any{"type": "string", "description": "the address the notifier posts to, a URL; unset, the notifier's own environment says it", "default": ""} resourceOf(m, "rules")["takes-config"] = []any{"position", "theme", map[string]any{"key": "url", "as": "NOTIFIER_URL"}} return m } func listHolds(list []string, s string) bool { for _, x := range list { if x == s { return true } } return false } func TestARenamedEntryIsWrittenBackAsItWasSaid(t *testing.T) { m, err := parseRaw(t, renaming()) if err != nil { t.Fatal(err) } raw, err := json.Marshal(m) if err != nil { t.Fatal(err) } if !strings.Contains(string(raw), `"takes-config":["position","theme",{"as":"NOTIFIER_URL","key":"url"}]`) { t.Fatalf("written back as %s", raw) } if _, err := decodeForTest(raw); err != nil { t.Fatalf("read again: %v", err) } }