32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package validate
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/declaration"
|
|
)
|
|
|
|
// The SDK's validator speaks the copied parser's vocabulary version (issue 1353 AC3).
|
|
func TestVersionIsTheParsersVersion(t *testing.T) {
|
|
if Version != declaration.Version {
|
|
t.Fatalf("validate.Version = %d, declaration.Version = %d", Version, declaration.Version)
|
|
}
|
|
}
|
|
|
|
// A body of another declaration version is refused whole, by both the validator and the parser (AC3). The body is
|
|
// the shape mesh-host's validate_test.go uses for its good declaration, with the version changed.
|
|
func TestAnotherVersionIsRefusedWhole(t *testing.T) {
|
|
body := `{"declaration": 99, "resources": [{"id": "d", "type": "directory", "path": "/var/lib/x", "mode": "0755"}]}`
|
|
problems := Declaration([]byte(body))
|
|
if len(problems) == 0 {
|
|
t.Fatal("a declaration of another version was taken")
|
|
}
|
|
_, err := declaration.Parse([]byte(body))
|
|
var refused *declaration.RefusalError
|
|
if !errors.As(err, &refused) || strings.Join(refused.Problems, "\n") != strings.Join(problems, "\n") {
|
|
t.Fatalf("the parser and the validator disagree: %v / %v", err, problems)
|
|
}
|
|
}
|