- 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
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package kiosk_test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/kiosk"
|
|
)
|
|
|
|
// Marshal writes the plugin.yaml bytes: the generated header, the fields
|
|
// in a fixed order and the required plugins sorted by ID.
|
|
func ExampleMarshal() {
|
|
out, err := kiosk.Marshal(kiosk.Manifest{
|
|
Schema: kiosk.SchemaVersion,
|
|
ID: "acme.shop",
|
|
Module: "example.test/sm-shop-plugin",
|
|
Package: "example.test/sm-shop-plugin",
|
|
Name: "Shop",
|
|
Description: "Products, carts and orders.",
|
|
Framework: "v0.6.0",
|
|
Requires: kiosk.Requires{"acme.user": "v0.1.2", "acme.payment": ""},
|
|
})
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Print(string(out))
|
|
// Output:
|
|
// # Generated by summer plugin:manifest. Do not edit; rerun the command.
|
|
// schema: 1
|
|
// id: acme.shop
|
|
// module: example.test/sm-shop-plugin
|
|
// package: example.test/sm-shop-plugin
|
|
// name: Shop
|
|
// description: Products, carts and orders.
|
|
// framework: v0.6.0
|
|
// requires:
|
|
// acme.payment: ""
|
|
// acme.user: v0.1.2
|
|
}
|
|
|
|
// NewestCompatible picks the newest release whose framework minimum the
|
|
// application's framework meets; the list order does not matter.
|
|
func ExampleNewestCompatible() {
|
|
versions := []kiosk.RegistryVersion{
|
|
{Version: "v0.3.0", Framework: "v0.7.0"},
|
|
{Version: "v0.2.1", Framework: "v0.6.0"},
|
|
{Version: "v0.1.0", Framework: "v0.5.0"},
|
|
}
|
|
for _, framework := range []string{"v0.6.2", "v0.7.0", "v0.4.0"} {
|
|
v, ok := kiosk.NewestCompatible(versions, framework)
|
|
fmt.Println(framework, v.Version, ok)
|
|
}
|
|
// Output:
|
|
// v0.6.2 v0.2.1 true
|
|
// v0.7.0 v0.3.0 true
|
|
// v0.4.0 false
|
|
}
|