package config import ( "os" "path/filepath" "strings" "testing" ) const sample = `credentials: twitter: oauth2_access_token: "old-access" oauth2_refresh_token: "old-refresh" linkedin: access_token: "" author_urn: "" ` func TestUpdateTokensDoesNotTouchOtherSections(t *testing.T) { path := filepath.Join(t.TempDir(), "config.yaml") if err := os.WriteFile(path, []byte(sample), 0600); err != nil { t.Fatal(err) } if err := UpdateOAuth2Tokens(path, "new-access", "new-refresh"); err != nil { t.Fatal(err) } if err := UpdateLinkedInCredentials(path, "li-token", "urn:li:person:1"); err != nil { t.Fatal(err) } data, _ := os.ReadFile(path) got := string(data) for _, want := range []string{ `oauth2_access_token: "new-access"`, `oauth2_refresh_token: "new-refresh"`, ` access_token: "li-token"`, `author_urn: "urn:li:person:1"`, } { if !strings.Contains(got, want) { t.Errorf("missing %q in:\n%s", want, got) } } }