2023-03-22 20:48:09 +01:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2023-10-19 20:05:59 +02:00
|
|
|
"os"
|
2023-03-22 20:48:09 +01:00
|
|
|
"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(
|
2023-04-05 15:12:51 +02:00
|
|
|
func(ctx context.Context, id app.ID, from string) (string, error) {
|
|
|
|
return fmt.Sprintf("http//%s.example.com?from=%s", id, from), nil
|
2023-03-22 20:48:09 +01:00
|
|
|
},
|
|
|
|
&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-03-22 20:48:09 +01:00
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
data, err := os.ReadFile(script)
|
2023-03-22 20:48:09 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-10-19 20:05:59 +02:00
|
|
|
ctx := context.Background()
|
2023-11-28 16:35:49 +01:00
|
|
|
if err := server.Start(ctx, script, string(data)); err != nil {
|
2023-03-22 20:48:09 +01:00
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
2023-11-28 16:35:49 +01:00
|
|
|
|
|
|
|
defer server.Stop()
|
2023-03-22 20:48:09 +01:00
|
|
|
}
|