edge/pkg/module/app/memory/module_test.go

56 lines
1.2 KiB
Go
Raw Permalink Normal View History

package memory
import (
"context"
"fmt"
"os"
"testing"
"forge.cadoles.com/arcad/edge/pkg/app"
"forge.cadoles.com/arcad/edge/pkg/module"
appModule "forge.cadoles.com/arcad/edge/pkg/module/app"
"github.com/pkg/errors"
)
func TestAppModuleWithMemoryRepository(t *testing.T) {
t.Parallel()
server := app.NewServer(
module.ContextModuleFactory(),
module.ConsoleModuleFactory(),
appModule.ModuleFactory(NewRepository(
func(ctx context.Context, id app.ID, from string) (string, error) {
return fmt.Sprintf("http//%s.example.com?from=%s", id, from), nil
},
&app.Manifest{
ID: "dummy1.arcad.app",
Version: "0.0.0",
Title: "Dummy 1",
Description: "Dummy App 1",
Tags: []string{"dummy", "first"},
},
&app.Manifest{
ID: "dummy2.arcad.app",
Version: "0.0.0",
Title: "Dummy 2",
Description: "Dummy App 2",
Tags: []string{"dummy", "second"},
},
)),
)
2023-11-28 16:35:49 +01:00
script := "testdata/app.js"
2023-11-28 16:35:49 +01:00
data, err := os.ReadFile(script)
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
2023-11-28 16:35:49 +01:00
if err := server.Start(ctx, script, string(data)); err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
2023-11-28 16:35:49 +01:00
defer server.Stop()
}