Пример #1
0
func TestAddMutationRoot(t *testing.T) {
	cb, _ := data.Setup(t)
	a := node.NewNode()
	ty, ok := system.GetTypeFromCache(cb.Ctx(), "kego.io/tests/data", "multi")
	require.True(t, ok)
	require.NoError(t, mutateAddNode(cb.Ctx(), a, nil, "", 2, ty, "z"))
	require.NotNil(t, a.Value.(*data.Multi).Id)
	require.Equal(t, "z", a.Value.(*data.Multi).Id.Name)
}
Пример #2
0
func TestView_Receive(t *testing.T) {
	m := gomock.NewController(t)
	defer m.Finish()
	ctx := context.Background()
	app := mock_flux.NewMockAppInterface(m)
	c := make(chan flux.NotifPayload)
	app.EXPECT().Watch("a", notif1{}).Return(c)
	v := NewTestView(ctx, app, true)
	v.Body = vecty.Nil()
	np := flux.NotifPayload{Done: make(chan struct{}, 1)}
	v.Notifs[0] <- np
	<-np.Done
	require.True(t, v.received)
}
Пример #3
0
func TestNode_Unpack(t *testing.T) {

	cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse)

	s := `{
	"type": "multi",
	"js": "a"
}`

	n := node.NewNode()
	require.NoError(t, n.Unpack(cb.Ctx(), system.MustPackString(s), false))
	m, ok := n.Value.(*data.Multi)
	require.True(t, ok)
	assert.Equal(t, "a", m.Js)

}
Пример #4
0
func TestUnmarshal(t *testing.T) {

	cb := tests.Context("kego.io/tests/data").Jauto().Sauto(parser.Parse)

	s := `{
	"type": "simple",
	"js": "a"
}`

	n, err := node.Unmarshal(cb.Ctx(), []byte(s))
	require.NoError(t, err)
	m, ok := n.Value.(*data.Simple)
	require.True(t, ok)
	assert.Equal(t, "a", m.Js)

}
Пример #5
0
func getErrData(t *testing.T, args []ast.Expr, arg int, file string, pos token.Position) *errDef {
	require.True(t, len(args) > arg, "Not enough args (%s:%d)", file, pos.Line)
	b, ok := args[arg].(*ast.BasicLit)
	if !ok {
		return nil
	}
	require.Equal(t, b.Kind, token.STRING, "kind should be token.STRING (%s:%d)", file, pos.Line)
	id, err := strconv.Unquote(b.Value)
	require.NoError(t, err, "Error unquoting arg (%s:%d)", file, pos.Line)
	assert.True(t, ksrc.IsId(id), "Invalid kerr ID %s (%s:%d)", id, file, pos.Line)
	def, ok := all[id]
	if ok {
		return def
	}
	def = &errDef{}
	def.id = id
	all[id] = def
	return def
}
Пример #6
0
func TestAddMutationRedo(t *testing.T) {
	cb, n := data.Setup(t)

	test := func(t *testing.T, n *node.Node, m *data.Multi) {

		var a, p, b, a1, p1, b1 *node.Node
		a = node.NewNode()
		p = n.Map["am"]
		b = node.NewNode()
		ty, ok := system.GetTypeFromCache(cb.Ctx(), "kego.io/tests/data", "multi")
		require.True(t, ok)
		require.NoError(t, mutateAddNode(cb.Ctx(), a, p, "", 2, ty, ""))
		require.Equal(t, `[{"js":"amjs0","type":"multi"},{"js":"amjs1","type":"multi"},{"type":"multi"}]`, p.Print(cb.Ctx()))

		a1 = n.Map["am"].Array[2].Map["m"]
		p1 = n.Map["am"].Array[2]
		b1 = node.NewNode()
		require.NoError(t, mutateAddNode(cb.Ctx(), a1, p1, "m", -1, ty, ""))
		require.Equal(t, 3, len(n.Map["am"].Array))
		require.Equal(t, 3, len(m.Am))
		require.False(t, n.Map["am"].Array[2].Map["m"].Missing)
		require.Equal(t, `[{"js":"amjs0","type":"multi"},{"js":"amjs1","type":"multi"},{"m":{"type":"multi"},"type":"multi"}]`, p.Print(cb.Ctx()))

		require.NoError(t, mutateDeleteNode(cb.Ctx(), a, p, b))
		require.NoError(t, mutateDeleteNode(cb.Ctx(), a1, p1, b1))
		require.Equal(t, 2, len(n.Map["am"].Array))
		require.Equal(t, 2, len(m.Am))
		require.NoError(t, mutateRestoreNode(cb.Ctx(), a, p, b))
		require.NoError(t, mutateRestoreNode(cb.Ctx(), a1, p1, b1))
		require.Equal(t, 3, len(n.Map["am"].Array))
		require.Equal(t, 3, len(m.Am))
		require.NotNil(t, n.Map["am"].Array[2])
		require.NotNil(t, m.Am[2])
	}

	test(t, n.Map["m"], n.Value.(*data.Multi).M)
}