package creds import ( "encoding/json" "testing" ) func TestHostCreds_ActiveAccountRoundTrip(t *testing.T) { src := HostCreds{ Token: "tok", ActiveAccountID: "acct-uuid", ActiveAccountSlug: "acme", } b, err := json.Marshal(src) if err != nil { t.Fatalf("Marshal: %v", err) } var got HostCreds if err := json.Unmarshal(b, &got); err != nil { t.Fatalf("Unmarshal: %v", err) } if got.ActiveAccountID != "acct-uuid" { t.Errorf("ActiveAccountID = %q, want acct-uuid", got.ActiveAccountID) } if got.ActiveAccountSlug != "acme" { t.Errorf("ActiveAccountSlug = %q, want acme", got.ActiveAccountSlug) } } func TestHostCreds_LegacyFileLoadsWithoutAccount(t *testing.T) { // A creds.json from before the active-account fields existed must still // unmarshal cleanly; the new fields should be zero-valued. legacy := `{"token":"tok","user":"alice","default_scope":"@themes"}` var got HostCreds if err := json.Unmarshal([]byte(legacy), &got); err != nil { t.Fatalf("Unmarshal legacy: %v", err) } if got.Token != "tok" { t.Errorf("Token = %q", got.Token) } if got.ActiveAccountID != "" || got.ActiveAccountSlug != "" { t.Errorf("ActiveAccount* should be empty for legacy file, got id=%q slug=%q", got.ActiveAccountID, got.ActiveAccountSlug) } }