package validate import ( "strings" "testing" ) // **The validator a controller imports is the host's**: a declaration the host takes passes, and one // it refuses is refused with the host's own words, every problem at once. func TestTheValidatorIsTheHosts(t *testing.T) { good := `{"declaration": 1, "resources": [{"id": "d", "type": "directory", "path": "/var/lib/x", "mode": "0755"}]}` if problems := Declaration([]byte(good)); problems != nil { t.Fatalf("a declaration the host takes was refused: %v", problems) } // And one carrying the lease epoch and sequence the controller sends it under (novox/hq to-be 45 // ยง6): a controller validating with this package may send them. ordered := `{"declaration": 1, "epoch": 57, "sequence": 3, "resources": [{"id": "d", "type": "directory", "path": "/var/lib/x", "mode": "0755"}]}` if problems := Declaration([]byte(ordered)); problems != nil { t.Fatalf("a declaration carrying its order was refused: %v", problems) } for _, bad := range []string{ `{"declaration": 1, "resources": []}`, `{"declaration": 99, "resources": [{"id": "d", "type": "directory", "path": "/x"}]}`, `{"declaration": 1, "resources": [{"id": "d", "type": "nothing-the-host-knows"}]}`, `not json`, } { problems := Declaration([]byte(bad)) if len(problems) == 0 { t.Errorf("a declaration the host refuses was passed: %s", bad) } for _, p := range problems { if strings.TrimSpace(p) == "" { t.Errorf("a problem said nothing, for %s", bad) } } } }