-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
63 lines (56 loc) · 1.12 KB
/
helpers_test.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
package cfgloader_test
import (
"os"
"path"
"testing"
)
type cfgStruct struct {
Foo string `yaml:"foo" json:"foo"`
Bar string `yaml:"bar" json:"bar"`
Int int `yaml:"int" json:"int"`
Float float64 `yaml:"float" json:"float"`
Baz struct {
Foo string `yaml:"foo" json:"foo"`
Bar string `yaml:"bar" json:"bar"`
Int int `yaml:"int" json:"int"`
Float float64 `yaml:"float" json:"float"`
} `yaml:"baz" json:"baz"`
}
var testSchema = []byte(`{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"foo": {
"type": "string",
"maxLength": 2
},
"bar": {
"type": "string",
"minLength": 1
},
"baz": {
"type": "object",
"properties": {
"foo": {
"type": "string"
},
"bar": {
"type": "string"
}
}
}
}
}
`)
func writeTempFile(t *testing.T, b []byte, ext string) (string, error) {
p := path.Join(t.TempDir(), "testFile"+ext)
f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE, 0o600)
if err != nil {
return "", err
}
defer f.Close()
if _, err = f.Write(b); err != nil {
return "", err
}
return p, nil
}