-
Notifications
You must be signed in to change notification settings - Fork 9
/
testoldsyntax.go
63 lines (51 loc) · 1.55 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
56
57
58
59
60
61
62
63
// 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/internal/parsing"
"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, pl parsing.EarlyPackageLoader, loc pkggraph.Location, parent, v *fncue.CueV) (*schema.Test, *schema.Binary, error) {
// Ensure all fields are bound.
if err := v.Val.Validate(cue.Concrete(true)); err != nil {
return nil, nil, err
}
test := cueTestOld{}
if err := v.Val.Decode(&test); err != nil {
return nil, nil, err
}
testDef := &schema.Test{
Name: test.Name,
ServersUnderTest: test.Fixture.ServersUnderTest,
}
var err error
var bin *schema.Binary
if test.Driver != nil {
bin, err = test.Driver.ToSchema(ctx, pl, loc)
} else if test.Binary != nil {
bin, err = test.Binary.ToSchema(ctx, pl, loc)
}
if err != nil {
return nil, nil, err
}
if bin.Name == "" {
bin.Name = test.Name
}
testDef.Driver = schema.MakePackageRef(loc.PackageName, bin.Name)
return testDef, bin, nil
}