47 lines
1.3 KiB
Go
47 lines
1.3 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", "manifest.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 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)
|
|
}
|
|
}
|
|
}
|