Compare commits
No commits in common. "6498f3d56b64495cf559350d5f9bb8fc4c1dc210" and "2b888f203d08d5713c0fdb5e08ef06d6844ab101" have entirely different histories.
6498f3d56b
...
2b888f203d
8 changed files with 1 additions and 242 deletions
14
app.go
14
app.go
|
|
@ -26,7 +26,6 @@ func NewApp(ver string, conf config.Config, db proc.Store) (*App, error) {
|
|||
}
|
||||
app := App{
|
||||
version: ver,
|
||||
conf: conf,
|
||||
}
|
||||
|
||||
selfIRI := boxap.DefaultServiceIRI(conf.BaseURL)
|
||||
|
|
@ -45,10 +44,6 @@ func (l *App) Config() config.Config {
|
|||
return l.conf
|
||||
}
|
||||
|
||||
func (l *App) Environment() config.Env {
|
||||
return l.conf.Environment()
|
||||
}
|
||||
|
||||
func (l *App) Storage() proc.Store {
|
||||
return l.storage
|
||||
}
|
||||
|
|
@ -69,13 +64,6 @@ func (l *App) Version() string {
|
|||
return l.version
|
||||
}
|
||||
|
||||
func (l *App) Name() string {
|
||||
if l.conf.Name == "" {
|
||||
return "Lenore"
|
||||
}
|
||||
return l.conf.Name
|
||||
}
|
||||
|
||||
func (l *App) String() string {
|
||||
return fmt.Sprintf("%s (%s)", l.Name(), l.version)
|
||||
return fmt.Sprintf("Lenore (%s)", l.version)
|
||||
}
|
||||
|
|
|
|||
89
app_test.go
89
app_test.go
|
|
@ -1,89 +0,0 @@
|
|||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,6 @@
|
|||
package config
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
Env Env
|
||||
BaseURL string
|
||||
}
|
||||
|
||||
func (c Config) Environment() Env {
|
||||
return ValidEnvOrDev(c.Env)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEnvDefaultsToDev(t *testing.T) {
|
||||
c := Config{}
|
||||
assert.Equal(t, DEV, c.Environment())
|
||||
}
|
||||
|
||||
func TestInvalidEnvReturnsDev(t *testing.T) {
|
||||
c := Config{Env: Env("foobar")}
|
||||
assert.Equal(t, DEV, c.Environment())
|
||||
}
|
||||
|
||||
func TestValidEnvReturnsCorrect(t *testing.T) {
|
||||
for _, e := range Envs {
|
||||
t.Run(string(e), func(t *testing.T) {
|
||||
c := Config{Env: e}
|
||||
assert.Equal(t, e, c.Environment())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEnvString(t *testing.T) {
|
||||
cases := Envs[:]
|
||||
cases = append(cases, Env("foobar"), Env(""), Env("42"), Env("✨"))
|
||||
for _, e := range cases {
|
||||
t.Run(string(e), func(t *testing.T) {
|
||||
assert.Equal(t, string(e), e.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidEnv(t *testing.T) {
|
||||
cases := [...]struct {
|
||||
e Env
|
||||
exp bool
|
||||
}{
|
||||
{DEV, true},
|
||||
{PROD, true},
|
||||
{QA, true},
|
||||
{TEST, true},
|
||||
{Env("foobar"), false},
|
||||
{Env(""), false},
|
||||
{Env("✨"), false},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(string(c.e), func(t *testing.T) {
|
||||
assert.Equal(t, c.exp, ValidEnv(c.e))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidEnvOrDev(t *testing.T) {
|
||||
cases := [...]struct {
|
||||
give Env
|
||||
exp Env
|
||||
}{
|
||||
{DEV, DEV},
|
||||
{PROD, PROD},
|
||||
{QA, QA},
|
||||
{TEST, TEST},
|
||||
{Env("foobar"), DEV},
|
||||
{Env(""), DEV},
|
||||
{Env("✨"), DEV},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(string(c.give), func(t *testing.T) {
|
||||
assert.Equal(t, c.exp, ValidEnvOrDev(c.give))
|
||||
})
|
||||
}
|
||||
}
|
||||
4
go.mod
4
go.mod
|
|
@ -8,7 +8,6 @@ require (
|
|||
github.com/go-ap/fedbox v0.0.0-20240910163620-7bcedb2eb399
|
||||
github.com/go-ap/processing v0.0.0-20240910151355-8284a5ce9c22
|
||||
github.com/go-ap/storage-sqlite v0.0.0-20240910151457-20fa80d963aa
|
||||
github.com/stretchr/testify v1.9.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
@ -16,7 +15,6 @@ require (
|
|||
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 // indirect
|
||||
git.sr.ht/~mariusor/lw v0.0.0-20240906100438-00d2184b2120 // indirect
|
||||
git.sr.ht/~mariusor/ssm v0.0.0-20240811085540-34f24cac52b7 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/go-ap/cache v0.0.0-20240910141827-94f8ac1a9133 // indirect
|
||||
github.com/go-ap/errors v0.0.0-20240910140019-1e9d33cc1568 // indirect
|
||||
|
|
@ -33,7 +31,6 @@ require (
|
|||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/openshift/osin v1.0.2-0.20220317075346-0f4d38c6e53f // indirect
|
||||
github.com/pborman/uuid v1.2.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/rs/zerolog v1.33.0 // indirect
|
||||
|
|
@ -42,7 +39,6 @@ require (
|
|||
golang.org/x/oauth2 v0.23.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
|
|
|
|||
8
go.sum
8
go.sum
|
|
@ -10,8 +10,6 @@ git.sr.ht/~mariusor/ssm v0.0.0-20240811085540-34f24cac52b7/go.mod h1:VApG24PG5Ij
|
|||
github.com/carlmjohnson/be v0.23.2 h1:1QjPnPJhwGUjsD9+7h98EQlKsxnG5TV+nnEvk0wnkls=
|
||||
github.com/carlmjohnson/be v0.23.2/go.mod h1:KAgPUh0HpzWYZZI+IABdo80wTgY43YhbdsiLYAaSI/Q=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
|
|
@ -77,8 +75,6 @@ github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
|||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
|
||||
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
|
@ -111,11 +107,7 @@ golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
|||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/square/go-jose.v1 v1.1.2/go.mod h1:QpYS+a4WhS+DTlyQIi6Ka7MS3SuR9a055rgXNEe6EiA=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a h1:CfbpOLEo2IwNzJdMvE8aiRbPMxoTpgAJeyePh0SmO8M=
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
package testmocks
|
||||
|
||||
import (
|
||||
vocab "github.com/go-ap/activitypub"
|
||||
"github.com/go-ap/filters"
|
||||
proc "github.com/go-ap/processing"
|
||||
)
|
||||
|
||||
type st struct{}
|
||||
|
||||
func (s *st) Load(iri vocab.IRI, filters ...filters.Check) (vocab.Item, error) {
|
||||
i := vocab.ActorNew(iri, vocab.ActorType)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (s *st) Save(v vocab.Item) (vocab.Item, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (s *st) Delete(v vocab.Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) Create(col vocab.CollectionInterface) (vocab.CollectionInterface, error) {
|
||||
return col, nil
|
||||
}
|
||||
|
||||
func (s *st) AddTo(col vocab.IRI, it vocab.Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) RemoveFrom(col vocab.IRI, it vocab.Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetStore() proc.Store {
|
||||
return &st{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue