-
Notifications
You must be signed in to change notification settings - Fork 9
/
testoldsyntax.go
55 lines (45 loc) · 1.3 KB
/
testoldsyntax.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package cuefrontend
import (
"context"
"cuelang.org/go/cue"
"namespacelabs.dev/foundation/internal/frontend/fncue"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
type cueTestOld struct {
Name string `json:"name"`
Binary *cueBinary `json:"binary"`
Driver *cueBinary `json:"driver"`
Fixture cueFixture `json:"fixture"`
}
type cueFixture struct {
ServersUnderTest []string `json:"serversUnderTest"`
}
// Old syntax
func parsecueTestOld(ctx context.Context, loc pkggraph.Location, parent, v *fncue.CueV) (*schema.Test, error) {
// Ensure all fields are bound.
if err := v.Val.Validate(cue.Concrete(true)); err != nil {
return nil, err
}
test := cueTestOld{}
if err := v.Val.Decode(&test); err != nil {
return nil, err
}
testDef := &schema.Test{
Name: test.Name,
ServersUnderTest: test.Fixture.ServersUnderTest,
}
var err error
if test.Driver != nil {
testDef.Driver, err = test.Driver.ToSchema(loc)
} else if test.Binary != nil {
testDef.Driver, err = test.Binary.ToSchema(loc)
}
if err != nil {
return nil, err
}
return testDef, nil
}