From c4ae2eda483fc1393f7d3ce6bcffdd23e19f1a9b Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 12 Nov 2023 17:51:15 +0100 Subject: [PATCH] Simple tests for Backend.FromConfig implementations --- backends/funkwhale/funkwhale_test.go | 8 +++++ backends/listenbrainz/listenbrainz_test.go | 8 +++++ backends/maloja/maloja_test.go | 8 +++++ backends/scrobblerlog/scrobblerlog_test.go | 37 ++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 backends/scrobblerlog/scrobblerlog_test.go diff --git a/backends/funkwhale/funkwhale_test.go b/backends/funkwhale/funkwhale_test.go index e5789c3..fbc3d98 100644 --- a/backends/funkwhale/funkwhale_test.go +++ b/backends/funkwhale/funkwhale_test.go @@ -25,11 +25,19 @@ import ( "testing" "time" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "go.uploadedlobster.com/scotty/backends/funkwhale" "go.uploadedlobster.com/scotty/models" ) +func TestFromConfig(t *testing.T) { + config := viper.New() + config.Set("token", "thetoken") + backend := funkwhale.FunkwhaleApiBackend{}.FromConfig(config) + assert.IsType(t, funkwhale.FunkwhaleApiBackend{}, backend) +} + func TestFunkwhaleListeningToListen(t *testing.T) { fwListen := funkwhale.Listening{ CreationDate: "2023-11-09T23:59:29.022005Z", diff --git a/backends/listenbrainz/listenbrainz_test.go b/backends/listenbrainz/listenbrainz_test.go index 924a4d0..96a2c6f 100644 --- a/backends/listenbrainz/listenbrainz_test.go +++ b/backends/listenbrainz/listenbrainz_test.go @@ -25,11 +25,19 @@ import ( "testing" "time" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "go.uploadedlobster.com/scotty/backends/listenbrainz" "go.uploadedlobster.com/scotty/models" ) +func TestFromConfig(t *testing.T) { + config := viper.New() + config.Set("token", "thetoken") + backend := listenbrainz.ListenBrainzApiBackend{}.FromConfig(config) + assert.IsType(t, listenbrainz.ListenBrainzApiBackend{}, backend) +} + func TestListenBrainzListenToListen(t *testing.T) { lbListen := listenbrainz.Listen{ ListenedAt: 1699289873, diff --git a/backends/maloja/maloja_test.go b/backends/maloja/maloja_test.go index 1ae90d6..1485f9b 100644 --- a/backends/maloja/maloja_test.go +++ b/backends/maloja/maloja_test.go @@ -25,10 +25,18 @@ import ( "testing" "time" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "go.uploadedlobster.com/scotty/backends/maloja" ) +func TestFromConfig(t *testing.T) { + config := viper.New() + config.Set("token", "thetoken") + backend := maloja.MalojaApiBackend{}.FromConfig(config) + assert.IsType(t, maloja.MalojaApiBackend{}, backend) +} + func TestScrobbleToListen(t *testing.T) { scrobble := maloja.Scrobble{ ListenedAt: 1699289873, diff --git a/backends/scrobblerlog/scrobblerlog_test.go b/backends/scrobblerlog/scrobblerlog_test.go new file mode 100644 index 0000000..0fa0c4d --- /dev/null +++ b/backends/scrobblerlog/scrobblerlog_test.go @@ -0,0 +1,37 @@ +/* +Copyright © 2023 Philipp Wolfer + +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 scrobblerlog_test + +import ( + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "go.uploadedlobster.com/scotty/backends/scrobblerlog" +) + +func TestFromConfig(t *testing.T) { + config := viper.New() + config.Set("token", "thetoken") + backend := scrobblerlog.ScrobblerLogBackend{}.FromConfig(config) + assert.IsType(t, scrobblerlog.ScrobblerLogBackend{}, backend) +}