43 lines
994 B
Go
43 lines
994 B
Go
package session
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestSaveLoadRoundTrip(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
path := filepath.Join(t.TempDir(), "session.json")
|
|
in := Data{
|
|
Spotify: SpotifyState{
|
|
ClientID: "abc123",
|
|
AccessToken: "access-token",
|
|
RefreshToken: "refresh-token",
|
|
ExpiresAt: "2026-01-02T03:04:05Z",
|
|
},
|
|
}
|
|
|
|
if err := Save(path, in); err != nil {
|
|
t.Fatalf("Save failed: %v", err)
|
|
}
|
|
|
|
out, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("Load failed: %v", err)
|
|
}
|
|
|
|
if out.Spotify.ClientID != in.Spotify.ClientID {
|
|
t.Fatalf("ClientID mismatch: got %q want %q", out.Spotify.ClientID, in.Spotify.ClientID)
|
|
}
|
|
if out.Spotify.AccessToken != in.Spotify.AccessToken {
|
|
t.Fatalf("AccessToken mismatch")
|
|
}
|
|
if out.Spotify.RefreshToken != in.Spotify.RefreshToken {
|
|
t.Fatalf("RefreshToken mismatch")
|
|
}
|
|
if out.Spotify.ExpiresAt != in.Spotify.ExpiresAt {
|
|
t.Fatalf("ExpiresAt mismatch: got %q want %q", out.Spotify.ExpiresAt, in.Spotify.ExpiresAt)
|
|
}
|
|
}
|