use go:embed to simplify testdata loading

This commit is contained in:
Philipp Wolfer 2023-12-10 14:11:54 +01:00
parent c4193f42a1
commit dd501df5c5
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
4 changed files with 35 additions and 25 deletions

View file

@ -23,8 +23,8 @@ THE SOFTWARE.
package spotify_test
import (
_ "embed"
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/assert"
@ -32,11 +32,12 @@ import (
"go.uploadedlobster.com/scotty/internal/backends/spotify"
)
//go:embed testdata/recently-played.json
var testRecentlyPlayed []byte
func TestRecentlyPlayedResult(t *testing.T) {
data, err := os.ReadFile("testdata/recently-played.json")
require.NoError(t, err)
result := spotify.RecentlyPlayedResult{}
err = json.Unmarshal(data, &result)
err := json.Unmarshal(testRecentlyPlayed, &result)
require.NoError(t, err)
assert := assert.New(t)