58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package contracts
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSharedContractIsOnlyRuntimeSource(t *testing.T) {
|
|
if _, err := os.Stat("local"); !os.IsNotExist(err) {
|
|
t.Fatal("contracts/local must not remain a parallel contract source")
|
|
}
|
|
out, err := exec.Command("git", "ls-files", "--stage", "--", "schema").CombinedOutput()
|
|
if err != nil || !strings.HasPrefix(string(out), "160000 ") {
|
|
t.Fatalf("contracts/schema must be a Git submodule: %s (%v)", out, err)
|
|
}
|
|
for _, name := range []string{"config-read.schema.json", "task-discovery.schema.json", "mq.schema.json", "mq-topology.json"} {
|
|
t.Run(name, func(t *testing.T) {
|
|
embedded, err := ReadCurrent(name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
shared, err := os.ReadFile("schema/" + name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(embedded, shared) {
|
|
t.Fatal("runtime contract differs from shared repository")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSharedContractExcludesLocalVerificationMaterials(t *testing.T) {
|
|
for _, name := range []string{"manifest.json", "verify.py", "test_verify.py", "examples/invalid/mq-string-tenant.json", "docs/archive/sources/v0.5-proposal.md"} {
|
|
if _, err := Files.ReadFile("schema/" + name); !os.IsNotExist(err) {
|
|
t.Errorf("verification material %s is embedded or cannot be checked: %v", name, err)
|
|
}
|
|
}
|
|
if _, err := ReadCurrent("manifest.json"); err == nil || !strings.Contains(err.Error(), "invalid current contract") {
|
|
t.Fatalf("local verification manifest must not be a runtime contract: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSharedEntrypointsReferenceCanonicalDefinitions(t *testing.T) {
|
|
for _, name := range []string{"config-read.schema.json", "task-discovery.schema.json", "mq.schema.json"} {
|
|
data, err := os.ReadFile("schema/" + name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Contains(data, []byte(".schema.json#")) {
|
|
t.Fatalf("%s must reference canonical split schemas, not copy their definitions", name)
|
|
}
|
|
}
|
|
}
|