Home

tmpl @d02502078f5c143f365e07447af8ca4f0a5f178c - refs - log -
-
https://git.jolheiser.com/tmpl.git
Template automation
tmpl / schema / schema_test.go
- raw
 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
package schema

import (
	"embed"
	"errors"
	"fmt"
	"testing"

	"github.com/matryer/is"
)

//go:embed testdata
var testdata embed.FS

func TestSchema(t *testing.T) {
	tt := []struct {
		Name   string
		NumErr int
	}{
		{Name: "good", NumErr: 0},
		{Name: "bad", NumErr: 10},
		{Name: "empty", NumErr: 1},
	}

	for _, tc := range tt {
		t.Run(tc.Name, func(t *testing.T) {
			assert := is.New(t)

			fi, err := testdata.Open(fmt.Sprintf("testdata/%s.yaml", tc.Name))
			assert.NoErr(err) // Should open test file

			err = Lint(fi)
			if tc.NumErr > 0 {
				var rerrs ResultErrors
				assert.True(errors.As(err, &rerrs))  // Error should be ResultErrors
				assert.True(len(rerrs) == tc.NumErr) // Number of errors should match test case
			} else {
				assert.NoErr(err) // Good schemas shouldn't return errors
			}
		})
	}
}