test(kiosk): manifest, identity, version and client unit tests
- TestReadIdentity: literal, const, chained, cross-package, alias, other-module and Requires shapes; refusals naming ID()/Requires() - TestDerive, TestManifestFormat, TestCheck, TestVersions, TestRegistryClient (httptest: escaping, 404, envelopes, cap, redirect) - runnable ExampleMarshal and ExampleNewestCompatible - party TestDescribe: copy of the plugin list, publish once per app
This commit is contained in:
61
modules/party/info_test.go
Normal file
61
modules/party/info_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package party
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
)
|
||||
|
||||
// TestDescribe covers publishing the build-time plugin metadata.
|
||||
func TestDescribe(t *testing.T) {
|
||||
if err := Describe(nil, nil, "v0.6.0"); err == nil || !strings.Contains(err.Error(), "app is nil") {
|
||||
t.Errorf("Describe(nil) = %v", err)
|
||||
}
|
||||
|
||||
app := backpack.New(&compass.Config{})
|
||||
if _, ok := app.Lookup[Installed](); ok {
|
||||
t.Fatal("a fresh app already has Installed")
|
||||
}
|
||||
plugins := []Info{
|
||||
{ID: "acme.user", Module: "example.test/sm-user-plugin", Package: "example.test/sm-user-plugin", Name: "User", Version: "v0.1.2", Source: SourceModule},
|
||||
{ID: "acme.shop", Package: "example.test/app/plugins/acme/shop", Source: SourceLocal},
|
||||
}
|
||||
if err := Describe(app, plugins, "v0.6.0"); err != nil {
|
||||
t.Fatalf("Describe: %v", err)
|
||||
}
|
||||
// The caller's slice is copied: changing it later does not change
|
||||
// what the app published.
|
||||
plugins[0].Version = "v9.9.9"
|
||||
got, ok := app.Lookup[Installed]()
|
||||
if !ok {
|
||||
t.Fatal("Installed not published")
|
||||
}
|
||||
if got.Framework != "v0.6.0" || len(got.Plugins) != 2 || got.Plugins[0].Version != "v0.1.2" || got.Plugins[1].Source != SourceLocal {
|
||||
t.Errorf("Installed = %+v", got)
|
||||
}
|
||||
|
||||
// Describe publishes once per app (the generated main calls it once,
|
||||
// before Activate); a second call is refused and the first stays.
|
||||
if err := Describe(app, nil, "v0.7.0"); err == nil || !strings.Contains(err.Error(), "party:") {
|
||||
t.Errorf("second Describe = %v, want a duplicate error", err)
|
||||
}
|
||||
if again, _ := app.Lookup[Installed](); again.Framework != "v0.6.0" || len(again.Plugins) != 2 {
|
||||
t.Errorf("after a second Describe: %+v", again)
|
||||
}
|
||||
|
||||
empty := backpack.New(&compass.Config{})
|
||||
if err := Describe(empty, nil, ""); err != nil {
|
||||
t.Fatalf("Describe with no plugins: %v", err)
|
||||
}
|
||||
if got, ok := empty.Lookup[Installed](); !ok || got.Plugins == nil || len(got.Plugins) != 0 || got.Framework != "" {
|
||||
t.Errorf("empty Installed = %+v, %v", got, ok)
|
||||
}
|
||||
|
||||
for _, s := range []string{SourceModule, SourceSubmodule, SourceLocal} {
|
||||
if s == "" || strings.ToLower(s) != s {
|
||||
t.Errorf("source constant %q", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user