feat: add end 2 end tests

This commit is contained in:
Jon Lundy
2023-01-25 10:35:09 -07:00
parent f9a088269c
commit 0f504a98e9
13 changed files with 268 additions and 230 deletions

View File

@@ -4,7 +4,9 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/patrickmn/go-cache"
"github.com/sour-is/ev"
"github.com/sour-is/ev/app/webfinger"
"github.com/sour-is/ev/internal/lg"
@@ -13,6 +15,11 @@ import (
"github.com/sour-is/ev/pkg/slice"
)
var (
defaultExpire = 3 * time.Minute
cleanupInterval = 10 * time.Minute
)
var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error {
ctx, span := lg.Span(ctx)
defer span.End()
@@ -23,12 +30,17 @@ var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error
return fmt.Errorf("*es.EventStore not found in services")
}
wf, err := webfinger.New(
ctx,
eventstore,
webfinger.WithHostnames(
strings.Fields(env.Default("WEBFINGER_DOMAINS", "sour.is")),
))
cache := cache.New(defaultExpire, cleanupInterval)
var withCache webfinger.WithCache = (func(s string) bool {
if _, ok := cache.Get(s); ok {
return true
}
cache.SetDefault(s, true)
return false
})
var withHostnames webfinger.WithHostnames = strings.Fields(env.Default("WEBFINGER_DOMAINS", "sour.is"))
wf, err := webfinger.New(ctx, eventstore, withCache, withHostnames)
if err != nil {
span.RecordError(err)
return err

View File

@@ -21,17 +21,21 @@ func main() {
<-ctx.Done()
defer cancel() // restore interrupt function
}()
if err := Run(ctx); err != nil {
log.Fatal(err)
os.Exit(1)
}
}
func Run(ctx context.Context) error {
svc := &service.Harness{}
ctx, stop := lg.Init(ctx, appName)
svc.OnStop(stop)
svc.Add(lg.NewHTTP(ctx))
svc.Setup(ctx, apps.Apps()...)
// Run application
if err := svc.Run(ctx, appName, version); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
return err
}
return nil
}