The node-engine held 1,707 top-level unit tests against the budget of 500 a module. Each unit test file with two or more tests now runs them as subtests of one test named for the file, each named as its function was, in the same order: every check is kept, and the check counts 383. Files with a TestMain, a re-run of a test by its name, or the integration tag are left. Four files of this branch's earlier commits are formatted. Builds: design 47 H2 §819; H-A-349 DQ-14
38 lines
1.4 KiB
Go
38 lines
1.4 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)
|
|
}
|
|
}
|
|
|
|
// TestSdk runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestSdk(t *testing.T) {
|
|
t.Run("VersionIsTheParsersVersion", testVersionIsTheParsersVersion)
|
|
t.Run("AnotherVersionIsRefusedWhole", testAnotherVersionIsRefusedWhole)
|
|
}
|