mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 10:09:28 +02:00
64 lines
2.3 KiB
Go
64 lines
2.3 KiB
Go
/*
|
|
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
package subsonic_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
go_subsonic "github.com/delucks/go-subsonic"
|
|
"github.com/spf13/viper"
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uploadedlobster.com/scotty/backends/subsonic"
|
|
)
|
|
|
|
func TestFromConfig(t *testing.T) {
|
|
config := viper.New()
|
|
config.Set("server-url", "https://subsonic.example.com")
|
|
config.Set("token", "thetoken")
|
|
backend := (&subsonic.SubsonicApiBackend{}).FromConfig(config)
|
|
assert.IsType(t, &subsonic.SubsonicApiBackend{}, backend)
|
|
}
|
|
|
|
func TestSongToLove(t *testing.T) {
|
|
user := "outsidecontext"
|
|
song := go_subsonic.Child{
|
|
Starred: time.Unix(1699574369, 0),
|
|
Title: "Oweynagat",
|
|
Album: "Here Now, There Then",
|
|
Artist: "Dool",
|
|
Duration: 414,
|
|
Genre: "psychedelic rock",
|
|
DiscNumber: 1,
|
|
Track: 5,
|
|
}
|
|
love := subsonic.SongToLove(song, user)
|
|
assert := assert.New(t)
|
|
assert.Equal(time.Unix(1699574369, 0).Unix(), love.Created.Unix())
|
|
assert.Equal(user, love.UserName)
|
|
assert.Equal(time.Duration(414*time.Second), love.Duration)
|
|
assert.Equal(song.Title, love.TrackName)
|
|
assert.Equal(song.Album, love.ReleaseName)
|
|
assert.Equal([]string{song.Artist}, love.ArtistNames)
|
|
assert.Equal(song.Track, love.Track.TrackNumber)
|
|
assert.Equal([]string{song.Genre}, love.Track.Tags)
|
|
}
|