mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
use go:embed to simplify testdata loading
This commit is contained in:
parent
c4193f42a1
commit
dd501df5c5
4 changed files with 35 additions and 25 deletions
|
@ -18,8 +18,8 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package spotify_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -30,6 +30,13 @@ import (
|
|||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed testdata/listen.json
|
||||
testListen []byte
|
||||
//go:embed testdata/track.json
|
||||
testTrack []byte
|
||||
)
|
||||
|
||||
func TestFromConfig(t *testing.T) {
|
||||
c := viper.New()
|
||||
c.Set("client-id", "someclientid")
|
||||
|
@ -40,10 +47,8 @@ func TestFromConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSpotifyListenAsListen(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/listen.json")
|
||||
require.NoError(t, err)
|
||||
spListen := spotify.Listen{}
|
||||
err = json.Unmarshal(data, &spListen)
|
||||
err := json.Unmarshal(testListen, &spListen)
|
||||
require.NoError(t, err)
|
||||
listen := spListen.AsListen()
|
||||
listenedAt, _ := time.Parse(time.RFC3339, "2023-11-21T15:24:33.361Z")
|
||||
|
@ -65,10 +70,8 @@ func TestSpotifyListenAsListen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSavedTrackAsLove(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/track.json")
|
||||
require.NoError(t, err)
|
||||
track := spotify.SavedTrack{}
|
||||
err = json.Unmarshal(data, &track)
|
||||
err := json.Unmarshal(testTrack, &track)
|
||||
require.NoError(t, err)
|
||||
love := track.AsLove()
|
||||
created, _ := time.Parse(time.RFC3339, "2022-02-13T21:46:08Z")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue