mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
Moved specifc backends into separate packages
This commit is contained in:
parent
dfaf21b234
commit
48c8843f91
17 changed files with 127 additions and 98 deletions
71
backends/backends_test.go
Normal file
71
backends/backends_test.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
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 backends_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uploadedlobster.com/scotty/backends"
|
||||
"go.uploadedlobster.com/scotty/backends/dump"
|
||||
"go.uploadedlobster.com/scotty/models"
|
||||
)
|
||||
|
||||
func TestResolveBackend(t *testing.T) {
|
||||
config := viper.New()
|
||||
config.Set("backend", "dump")
|
||||
backend, err := backends.ResolveBackend[models.ListenImport](config)
|
||||
assert.NoError(t, err)
|
||||
assert.IsType(t, dump.DumpBackend{}, backend)
|
||||
}
|
||||
|
||||
func TestResolveBackendUnknown(t *testing.T) {
|
||||
config := viper.New()
|
||||
config.Set("backend", "foo")
|
||||
_, err := backends.ResolveBackend[models.ListenImport](config)
|
||||
assert.EqualError(t, err, "Unknown backend foo")
|
||||
}
|
||||
|
||||
func TestResolveBackendInvalidInterface(t *testing.T) {
|
||||
config := viper.New()
|
||||
config.Set("backend", "dump")
|
||||
_, err := backends.ResolveBackend[models.ListenExport](config)
|
||||
assert.EqualError(t, err, "Backend dump does not implement ListenExport")
|
||||
}
|
||||
|
||||
func TestGetBackends(t *testing.T) {
|
||||
backends := backends.GetBackends()
|
||||
for _, info := range backends {
|
||||
if info.Name == "dump" {
|
||||
assert.Containsf(t, info.ImportCapabilities, "listen",
|
||||
"ImportCapabilities for \"dump\" expected to contain \"listens\"")
|
||||
assert.Emptyf(t, info.ExportCapabilities,
|
||||
"ExportCapabilities for \"dump\" expected to be empty")
|
||||
return // Finish the test
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here the "dump" backend was not included
|
||||
t.Errorf("GetBackends() did not return expected bacend \"dump\"")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue