1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package spotify
-
- import (
- "os"
- "strings"
- "testing"
- )
-
- func getAuthorization() (string, string) {
- envVars := os.Environ()
- for _, envVar := range envVars {
- key_val := strings.Split(envVar, "=")
- if key_val[0] == "SPOTIFY_TOKEN" {
- username_secret := strings.Split(key_val[1], ":")
- return username_secret[0], username_secret[1]
- }
- }
- return "", ""
- }
-
- func createClient(t *testing.T) *SpotifyClient {
- username, secret := getAuthorization()
- if username == "" {
- t.Fatal("Spotify authorization token not available, please use it as env variable SPOTIFY_TOKEN")
- }
- client := NewClient(username, secret)
- err := client.Authenticate()
- if err != nil {
- t.Fatal("Spotify authentication failed", err)
- }
- return client
- }
-
- func TestGetTrackInfo(t *testing.T) {
- client := createClient(t)
- track, err := client.GetTrack("5fLiaYOzIAk0PpwJ2VQUpT")
- if err != nil {
- t.Error("Error while reading Track", err)
- }
- if track.Artists[0].Name != "Vesala" {
- t.Error("Expected track artist to be 'Vesala'")
- }
- if track.Name != "Rakkaus ja maailmanloppu" {
- t.Error("Expected track artist to be 'Rakkaus ja maailmanloppu'")
- }
- if track.ExternalUrls.Spotify != "https://open.spotify.com/track/5fLiaYOzIAk0PpwJ2VQUpT" {
- t.Error("Expected track artist to be 'https://open.spotify.com/track/5fLiaYOzIAk0PpwJ2VQUpT'")
- }
- }
|