Exemple #1
0
func TestNode_SetIdField(t *testing.T) {
	cb, n := data.Setup(t)
	test := func(t *testing.T, n *node.Node, m *data.Multi) {
		require.HasError(t, n.Map["js"].SetIdField(cb.Ctx(), "a"), "QVLAEAEWEB")
		require.NoError(t, n.Map["m"].SetIdField(cb.Ctx(), "a"))
		require.Equal(t, "a", n.Map["m"].Value.(*data.Multi).Id.Name)
	}

	data.Run(t, n, n.Value.(*data.Multi), test)
}
Exemple #2
0
func TestAlmjsiError(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Note: map alias types in interfaces are always marshalled to explicit
	// object notation, so this throws an error.
	Run(t, ctx, `{
			"type": "multi",
			"almjsi": {"a": "b", "c": "d"}
		}`,
		UnmarshalError(func(t *testing.T, err error) {
			require.IsError(t, err, "SVXYHJWMOC")
			require.HasError(t, err, "RXEPCCGFKV")
		}),
	)
}
Exemple #3
0
func TestAlsError(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)
	// Type must be als when unpacking into als, even if it's an alias
	// of simple
	Run(t, ctx, `{
			"type": "multi",
			"als": {"type": "simple", "js": "a"}
		}`,
		UnmarshalError(func(t *testing.T, err error) {
			require.IsError(t, err, "SVXYHJWMOC")
			require.HasError(t, err, "BNHVLQPFKC")
		}),
	)
}
Exemple #4
0
func TestUnpackInterface(t *testing.T) {
	ctx := ke.NewContext(context.Background(), "kego.io/tests/data", nil)

	Run(t, ctx, `{
			"type": "aljb",
			"value": true
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, true, bool(*v.(*data.Aljb)))
		}),
	)

	Run(t, ctx, `meh`,
		UnmarshalError(func(t *testing.T, err error) {
			require.IsError(t, err, "SVXYHJWMOC")
			require.HasError(t, err, "PDTPGAYXRX")
		}),
	)

	Run(t, ctx, `{
			"type": "multi",
			"sri": "a"
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, "a", v.(*data.Multi).Sri.GetString(ctx).String())
		}),
	)

	Run(t, ctx, `{
			"type": "multi",
			"sri": {"type": "system:string", "value": "a"}
		}`,
		TestValue(func(t *testing.T, v interface{}) {
			assert.Equal(t, "a", v.(*data.Multi).Sri.GetString(ctx).String())
		}),
		MarshalledString(`{
			"type": "multi",
			"sri": "a"
		}`),
	)
}