mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
Restructured code, moved all modules into internal
For now all modules are considered internal. This might change later
This commit is contained in:
parent
f94e0f1e85
commit
857661ebf9
76 changed files with 121 additions and 68 deletions
70
internal/backends/deezer/deezer_test.go
Normal file
70
internal/backends/deezer/deezer_test.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
||||
|
||||
Scotty is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Scotty is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Scotty. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package deezer_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uploadedlobster.com/scotty/internal/backends/deezer"
|
||||
)
|
||||
|
||||
func TestFromConfig(t *testing.T) {
|
||||
config := viper.New()
|
||||
config.Set("client-id", "someclientid")
|
||||
config.Set("client-secret", "someclientsecret")
|
||||
backend := (&deezer.DeezerApiBackend{}).FromConfig(config)
|
||||
assert.IsType(t, &deezer.DeezerApiBackend{}, backend)
|
||||
}
|
||||
|
||||
func TestListenAsListen(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/listen.json")
|
||||
require.NoError(t, err)
|
||||
track := deezer.Listen{}
|
||||
err = json.Unmarshal(data, &track)
|
||||
require.NoError(t, err)
|
||||
listen := track.AsListen()
|
||||
assert.Equal(t, time.Unix(1700753817, 0), listen.ListenedAt)
|
||||
assert.Equal(t, time.Duration(268*time.Second), listen.Duration)
|
||||
assert.Equal(t, "New Divide", listen.TrackName)
|
||||
assert.Equal(t, "New Divide (Int'l DMD Maxi)", listen.ReleaseName)
|
||||
assert.Equal(t, "Linkin Park", listen.ArtistName())
|
||||
assert.Equal(t, "deezer.com", listen.AdditionalInfo["music_service"])
|
||||
assert.Equal(t, "https://www.deezer.com/track/14631511", listen.AdditionalInfo["origin_url"])
|
||||
assert.Equal(t, "https://www.deezer.com/track/14631511", listen.AdditionalInfo["deezer_id"])
|
||||
}
|
||||
|
||||
func TestLovedTrackAsLove(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/track.json")
|
||||
require.NoError(t, err)
|
||||
track := deezer.LovedTrack{}
|
||||
err = json.Unmarshal(data, &track)
|
||||
require.NoError(t, err)
|
||||
love := track.AsLove()
|
||||
assert.Equal(t, time.Unix(1700743848, 0), love.Created)
|
||||
assert.Equal(t, time.Duration(255*time.Second), love.Duration)
|
||||
assert.Equal(t, "Never Take Me Alive", love.TrackName)
|
||||
assert.Equal(t, "Outland", love.ReleaseName)
|
||||
assert.Equal(t, "Spear Of Destiny", love.ArtistName())
|
||||
assert.Equal(t, "deezer.com", love.AdditionalInfo["music_service"])
|
||||
assert.Equal(t, "https://www.deezer.com/track/3265090", love.AdditionalInfo["origin_url"])
|
||||
assert.Equal(t, "https://www.deezer.com/track/3265090", love.AdditionalInfo["deezer_id"])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue