89 lines
2.2 KiB
Go
89 lines
2.2 KiB
Go
package lenore
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"codeberg.org/danjones000/lenore/config"
|
|
"codeberg.org/danjones000/lenore/internal/testmocks"
|
|
vocab "github.com/go-ap/activitypub"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEmptyBaseURL(t *testing.T) {
|
|
c := config.Config{}
|
|
a, er := NewApp("0.0.0", c, testmocks.GetStore())
|
|
assert.Nil(t, a)
|
|
assert.EqualError(t, er, "missing BaseURL")
|
|
}
|
|
|
|
func TestDefaultEnvironment(t *testing.T) {
|
|
c := config.Config{BaseURL: "http://localhost:1234/"}
|
|
a, er := NewApp("0.0.0", c, testmocks.GetStore())
|
|
assert.NoError(t, er)
|
|
if assert.NotNil(t, a) {
|
|
assert.Equal(t, config.DEV, a.Environment())
|
|
}
|
|
}
|
|
|
|
func TestGivenEnvironment(t *testing.T) {
|
|
cases := [...]struct {
|
|
given config.Env
|
|
exp config.Env
|
|
}{
|
|
{config.DEV, config.DEV},
|
|
{config.PROD, config.PROD},
|
|
{config.QA, config.QA},
|
|
{config.Env("foo"), config.DEV},
|
|
{config.Env("✨"), config.DEV},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(string(c.given), func(t *testing.T) {
|
|
conf := config.Config{BaseURL: "http://localhost:1234/", Env: c.given}
|
|
a, er := NewApp("0.0.0", conf, testmocks.GetStore())
|
|
assert.NoError(t, er)
|
|
if assert.NotNil(t, a) {
|
|
assert.Equal(t, conf, a.Config())
|
|
assert.Equal(t, c.exp, a.Environment())
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestService(t *testing.T) {
|
|
base := "http://localhost:1234/"
|
|
conf := config.Config{BaseURL: base}
|
|
a, er := NewApp("0.0.0.0", conf, testmocks.GetStore())
|
|
assert.NoError(t, er)
|
|
if assert.NotNil(t, a) {
|
|
assert.Equal(t, vocab.IRI(base), a.ServiceIRI())
|
|
assert.Equal(t, vocab.IRI(base), a.Service().ID)
|
|
}
|
|
}
|
|
|
|
func TestStrings(t *testing.T) {
|
|
cases := [...]struct {
|
|
given string
|
|
exp string
|
|
}{
|
|
{"", "Lenore"},
|
|
{"Lenore", "Lenore"},
|
|
{"Danny Ray", "Danny Ray"},
|
|
{"✨👹", "✨👹"},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.given, func(t *testing.T) {
|
|
conf := config.Config{BaseURL: "http://localhost:1234/", Name: c.given}
|
|
expStr := fmt.Sprintf("%s (%s)", c.exp, "0.0.0.0")
|
|
a, er := NewApp("0.0.0.0", conf, testmocks.GetStore())
|
|
assert.NoError(t, er)
|
|
if assert.NotNil(t, a) {
|
|
assert.Equal(t, c.exp, a.Name())
|
|
assert.Equal(t, "0.0.0.0", a.Version())
|
|
assert.Equal(t, expStr, a.String())
|
|
}
|
|
})
|
|
}
|
|
}
|