示例#1
0
func TestList_Pull(t *testing.T) {
	lb := redis.NewList("users", conn)
	lb.Clean()

	attrs["Key"] = "user:1"
	ins1 := &Instance{Attrs: attrs}

	attrs["Key"] = "user:2"
	ins2 := &Instance{Attrs: attrs}

	attrs["Key"] = "user:3"
	ins3 := &Instance{Attrs: attrs}

	lb.Insert(ins1)
	lb.Insert(ins2)
	lb.Insert(ins3)

	users := []string{}

	for {
		u, err := lb.Pull()
		if err != nil {
			break
		}

		users = append(users, u)
	}

	if len(users) != 3 {
		t.Errorf("Want 3 got %d\n", len(users))
	}
}
示例#2
0
func TestList_Insert(t *testing.T) {
	lb := redis.NewList("users", conn)
	lb.Clean()

	err := lb.Insert(ins)
	if err != nil {
		t.Errorf("ERROR: %s\n", err)
	}

	if size := lb.Size(); size != 1 {
		t.Errorf("Want 1 got %d\n", size)
	}
}
示例#3
0
func TestList_Remove(t *testing.T) {
	lb := redis.NewList("users", conn)
	lb.Clean()

	lb.Insert(ins)

	key := ins.Marshal()
	lb.Remove(string(key))

	if size := lb.Size(); size != 0 {
		t.Errorf("Want 0 got %d\n", size)
	}
}