2023-04-05 23:21:43 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/app/spec"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateResolveAppURL(t *testing.T) {
|
|
|
|
specs := &spec.Spec{
|
|
|
|
Apps: map[string]spec.AppEntry{
|
|
|
|
"app.arcad.test": {
|
|
|
|
Address: ":8080",
|
|
|
|
},
|
2023-04-06 18:25:34 +02:00
|
|
|
"app.arcad.foo": {
|
|
|
|
Address: ":8081",
|
|
|
|
},
|
|
|
|
"app.arcad.bar": {
|
|
|
|
Address: ":8082",
|
|
|
|
},
|
2023-04-05 23:21:43 +02:00
|
|
|
},
|
|
|
|
Config: &spec.Config{
|
|
|
|
AppURLResolving: &spec.AppURLResolving{
|
|
|
|
IfaceMappings: map[string]string{
|
2023-04-06 15:55:51 +02:00
|
|
|
"lo": "http://{{ .DeviceIP }}:{{ .AppPort }}",
|
|
|
|
"does-not-exists": "http://{{ .DeviceIP }}:{{ .AppPort }}",
|
2023-04-05 23:21:43 +02:00
|
|
|
},
|
|
|
|
DefaultURLTemplate: `http://{{ last ( splitList "." ( toString .Manifest.ID ) ) }}.arcad.local`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveAppURL, err := createResolveAppURL(specs)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest := &app.Manifest{
|
|
|
|
ID: "app.arcad.test",
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
url, err := resolveAppURL(ctx, manifest, "127.0.0.2")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e, g := "http://127.0.0.1:8080", url; e != g {
|
|
|
|
t.Errorf("url: expected '%s', got '%s", e, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
url, err = resolveAppURL(ctx, manifest, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e, g := "http://test.arcad.local", url; e != g {
|
|
|
|
t.Errorf("url: expected '%s', got '%s", e, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
url, err = resolveAppURL(ctx, manifest, "192.168.0.100")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
if e, g := "http://test.arcad.local", url; e != g {
|
|
|
|
t.Errorf("url: expected '%s', got '%s", e, g)
|
|
|
|
}
|
|
|
|
}
|