Require exact schema version selection when validating documents
This commit is contained in:
@@ -16,15 +16,18 @@ func TestCommand(t *testing.T) {
|
||||
out string
|
||||
err string
|
||||
}{
|
||||
{"valid", []string{"-root", "../..", "../../examples/party.yml"}, 0, "valid (maximumdirect.rpg.party.v1)", ""},
|
||||
{"continue after failure", []string{"-root", "../..", "../../tests/invalid/semantic-duplicate-id.yml", "../../examples/weather.json"}, 1, "weather.json: valid", "semantic:"},
|
||||
{"structural", []string{"-root", "../..", "../../tests/invalid/structure-missing-name.yml"}, 1, "", "structure:"},
|
||||
{"decode", []string{"-root", "../..", "../../tests/invalid/decode-duplicate-key.yml"}, 1, "", "decode:"},
|
||||
{"file missing", []string{"-root", "../..", filepath.Join(t.TempDir(), "missing.yml")}, 1, "", "missing.yml"},
|
||||
{"valid", []string{"-root", "../..", "-schema", "rpg/party@0.1.0", "../../rpg/party/v0.1.0/examples/party.yml"}, 0, "valid (rpg/party@0.1.0; maximumdirect.rpg.party.v1)", ""},
|
||||
{"continue after failure", []string{"-root", "../..", "-schema", "glossary@0.1.0", "../../tests/invalid/semantic-duplicate-id.yml", "../../glossary/v0.1.0/examples/weather.json"}, 1, "weather.json: valid", "semantic:"},
|
||||
{"structural", []string{"-root", "../..", "-schema", "glossary@0.1.0", "../../tests/invalid/structure-missing-name.yml"}, 1, "", "structure:"},
|
||||
{"decode", []string{"-root", "../..", "-schema", "rpg/campaign@0.1.0", "../../tests/invalid/decode-duplicate-key.yml"}, 1, "", "decode:"},
|
||||
{"file missing", []string{"-root", "../..", "-schema", "rpg/campaign@0.1.0", filepath.Join(t.TempDir(), "missing.yml")}, 1, "", "missing.yml"},
|
||||
{"missing selection", []string{"-root", "../..", "../../rpg/party/v0.1.0/examples/party.yml"}, 2, "", "Usage:"},
|
||||
{"unknown selection", []string{"-root", "../..", "-schema", "rpg/party@9.0.0", "../../rpg/party/v0.1.0/examples/party.yml"}, 2, "", "schema selection:"},
|
||||
{"marker mismatch", []string{"-root", "../..", "-schema", "glossary@0.1.0", "../../rpg/party/v0.1.0/examples/party.yml"}, 1, "", "structure:"},
|
||||
{"no documents", nil, 2, "", "Usage:"},
|
||||
{"bad flag", []string{"-unknown"}, 2, "", "flag provided"},
|
||||
{"help", []string{"-h"}, 0, "", "Usage:"},
|
||||
{"missing set", []string{"-root", t.TempDir(), "../../examples/party.yml"}, 2, "", "schema set:"},
|
||||
{"missing set", []string{"-root", t.TempDir(), "-schema", "rpg/party@0.1.0", "../../rpg/party/v0.1.0/examples/party.yml"}, 2, "", "schema set:"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
@@ -42,7 +45,7 @@ func TestJSONSyntax(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stdout, stderr bytes.Buffer
|
||||
if run([]string{"-root", "../..", file}, &stdout, &stderr) != 1 || !strings.Contains(stderr.String(), "decode: expected JSON syntax") {
|
||||
if run([]string{"-root", "../..", "-schema", "rpg/campaign@0.1.0", file}, &stdout, &stderr) != 1 || !strings.Contains(stderr.String(), "decode: expected JSON syntax") {
|
||||
t.Fatalf("expected JSON syntax failure, got %q", &stderr)
|
||||
}
|
||||
}
|
||||
@@ -62,10 +65,10 @@ func TestDocumentDecoding(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stdout, stderr bytes.Buffer
|
||||
if code := run([]string{"-root", "../..", file}, &stdout, &stderr); code != test.code {
|
||||
if code := run([]string{"-root", "../..", "-schema", "rpg/campaign@0.1.0", file}, &stdout, &stderr); code != test.code {
|
||||
t.Fatalf("want exit %d, got %d: stdout=%q stderr=%q", test.code, code, &stdout, &stderr)
|
||||
}
|
||||
if test.code == 0 && !strings.Contains(stdout.String(), "valid (maximumdirect.rpg.campaign.v1)") {
|
||||
if test.code == 0 && !strings.Contains(stdout.String(), "valid (rpg/campaign@0.1.0; maximumdirect.rpg.campaign.v1)") {
|
||||
t.Fatalf("missing success report: %q", &stdout)
|
||||
}
|
||||
if test.code != 0 && !strings.Contains(stderr.String(), "decode:") {
|
||||
|
||||
Reference in New Issue
Block a user