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

59 lines
1.2 KiB
Go
Raw Permalink Normal View History

package memory
import (
"context"
"fmt"
"io/ioutil"
"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"},
},
)),
)
file := "testdata/app.js"
data, err := ioutil.ReadFile(file)
if err != nil {
t.Fatal(err)
}
if err := server.Load(file, string(data)); err != nil {
t.Fatal(err)
}
defer server.Stop()
if err := server.Start(); err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
}