Home

cuesonnet @59055bc6f4fbb5feba7916eff973da6eaf2bda09 - refs - log -
-
https://git.jolheiser.com/cuesonnet.git
CUE + Jsonnet
cuesonnet / cuesonnet_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
43
44
45
46
47
48
49
50
51
52
53
54
55
package cuesonnet_test

import (
	_ "embed"
	"strings"
	"testing"

	"go.jolheiser.com/cuesonnet"
)

var (
	//go:embed testdata/schema.cue
	schema cuesonnet.Schema
	//go:embed testdata/config.jsonnet
	config string
	//go:embed testdata/almost-fixed.jsonnet
	almostFixed string
	//go:embed testdata/fixed.jsonnet
	fixed string
)

func TestCUEsonnet(t *testing.T) {
	t.Run("config", func(t *testing.T) {
		t.Parallel()
		var m map[string]any
		err := schema.Decode(strings.NewReader(config), &m)
		for _, s := range []string{"2", "firstName", "age"} {
			if !strings.Contains(err.Error(), s) {
				t.Logf("did not find %q in error", s)
				t.Fail()
			}
		}
	})

	t.Run("almost-fixed", func(t *testing.T) {
		t.Parallel()
		var m map[string]any
		err := schema.Decode(strings.NewReader(almostFixed), &m)
		for _, s := range []string{"1", "LastName"} {
			if !strings.Contains(err.Error(), s) {
				t.Logf("did not find %q in error", s)
				t.Fail()
			}
		}
	})

	t.Run("fixed", func(t *testing.T) {
		t.Parallel()
		var m map[string]any
		if err := schema.Decode(strings.NewReader(fixed), &m); err != nil {
			t.Log("fixed config should not fail to decode")
			t.Fail()
		}
	})
}