forked from spigell/pulumi-hcloud-kube-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_test.go
46 lines (34 loc) · 952 Bytes
/
examples_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
package phkh
import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"github.com/spigell/pulumi-hcloud-kube-hetzner/internal/config"
"gopkg.in/yaml.v3"
"github.com/stretchr/testify/assert"
)
type PulumiConfig struct {
Config *config.Config `yaml:"config"`
}
func TestExampleWithUnknownFields(t *testing.T) {
exampleDir := "examples"
var decoded *PulumiConfig
files, err := os.ReadDir(exampleDir)
assert.NoError(t, err)
for _, f := range files {
if !strings.HasSuffix(f.Name(), ".yaml") {
continue
}
content, err := os.ReadFile(filepath.Join(exampleDir, f.Name()))
assert.NoError(t, err)
// Remove namespace from file
re := regexp.MustCompile("pulumi-hcloud-kube-hetzner:")
res := re.ReplaceAllString(string(content), "")
decoder := yaml.NewDecoder(strings.NewReader(res))
decoder.KnownFields(true)
assert.NoError(t, decoder.Decode(&decoded), fmt.Sprintf("%s failed to decode", f.Name()))
}
}