本文整理汇总了Golang中testutils.SetupTests函数的典型用法代码示例。如果您正苦于以下问题:Golang SetupTests函数的具体用法?Golang SetupTests怎么用?Golang SetupTests使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetupTests函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAddCML
func TestAddCML(t *testing.T) {
testutils.SetupTests()
defer testutils.TearDownTests()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(1000000)
info.Name = utils.Stringp("marvel")
typ := pb.SketchType_FREQ
info.Type = &typ
sketch, err := NewCMLSketch(info)
if err != nil {
t.Error("expected avengers to have no error, got", err)
}
values := [][]byte{
[]byte("sabertooth"),
[]byte("thunderbolt"),
[]byte("havoc"),
[]byte("cyclops"),
[]byte("cyclops"),
[]byte("cyclops"),
[]byte("havoc")}
if _, err := sketch.Add(values); err != nil {
t.Error("expected no errors, got", err)
}
if res, err := sketch.Get([][]byte{[]byte("cyclops")}); err != nil {
t.Error("expected no errors, got", err)
} else if res.(*pb.FrequencyResult).Frequencies[0].GetCount() != 3 {
t.Error("expected 'cyclops' count == 3, got", res.(*pb.FrequencyResult).Frequencies[0].GetCount())
}
}
示例2: TestStressBloom
func TestStressBloom(t *testing.T) {
testutils.SetupTests()
defer testutils.TearDownTests()
values := make([][]byte, 10)
for i := 0; i < 1024; i++ {
avenger := "avenger" + strconv.Itoa(i)
values = append(values, []byte(avenger))
}
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(1024)
info.Name = utils.Stringp("marvel")
sketch, err := NewBloomSketch(info)
for i := 0; i < 1024; i++ {
if err != nil {
t.Error("expected avengers to have no error, got", err)
}
if _, err := sketch.Add(values); err != nil {
t.Error("expected no errors, got", err)
}
}
}
示例3: TestDeleteSketch
func TestDeleteSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
m := NewManager()
info := datamodel.NewEmptyInfo()
typ := pb.SketchType_CARD
info.Properties.MaxUniqueItems = utils.Int64p(10000)
info.Name = utils.Stringp(fmt.Sprintf("marvel"))
info.Type = &typ
if err := m.CreateSketch(info); err != nil {
t.Error("Expected no errors, got", err)
}
if sketches := m.GetSketches(); len(sketches) != 1 {
t.Error("Expected 1 sketches, got", len(sketches))
} else if sketches[0][0] != "marvel" || sketches[0][1] != "card" {
t.Error("Expected [[marvel card]], got", sketches)
}
if err := m.DeleteSketch(info.ID()); err != nil {
t.Error("Expected no errors, got", err)
}
if sketches := m.GetSketches(); len(sketches) != 0 {
t.Error("Expected 0 sketches, got", len(sketches))
}
}
示例4: TestCreateDeleteDomain
func TestCreateDeleteDomain(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
m := NewManager()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(10000)
info.Properties.Size = utils.Int64p(10000)
info.Name = utils.Stringp(fmt.Sprintf("marvel"))
if err := m.CreateDomain(info); err != nil {
t.Error("Expected no errors, got", err)
}
if sketches := m.GetSketches(); len(sketches) != 4 {
t.Error("Expected 1 sketches, got", len(sketches))
} else if sketches[0][0] != "marvel" || sketches[0][1] != "card" {
t.Error("Expected [[marvel card]], got", sketches)
}
// Create a second Sketch
info2 := datamodel.NewEmptyInfo()
info2.Properties.MaxUniqueItems = utils.Int64p(10000)
info2.Name = utils.Stringp("dc")
if err := m.CreateDomain(info2); err != nil {
t.Error("Expected no errors, got", err)
}
if sketches := m.GetSketches(); len(sketches) != 8 {
t.Error("Expected 8 sketches, got", len(sketches))
} else if sketches[0][0] != "dc" || sketches[0][1] != "card" {
t.Error("Expected [[dc card]], got", sketches[0][0], sketches[0][1])
} else if sketches[1][0] != "dc" || sketches[1][1] != "freq" {
t.Error("Expected [[dc freq]], got", sketches[1][0], sketches[1][1])
}
}
示例5: TestCreateAddDeleteAddSketch
func TestCreateAddDeleteAddSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
client, conn := setupClient()
defer tearDownClient(conn)
typ := pb.SketchType_CARD
name := "yoyo"
in := &pb.Sketch{
Name: proto.String(name),
Type: &typ,
Properties: &pb.SketchProperties{
MaxUniqueItems: proto.Int64(1337), // FIXME: Allow default as -1
Size: proto.Int64(7),
},
}
addReq := &pb.AddRequest{
Sketch: in,
Values: []string{"a", "b", "c", "d", "a", "b"},
}
if _, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
}
typ = pb.SketchType_RANK
if _, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
}
if _, err := client.Add(context.Background(), addReq); err != nil {
t.Error("Did not expect error, got", err)
}
if res, err := client.ListAll(context.Background(), &pb.Empty{}); err != nil {
t.Error("Did not expect error, got", err)
} else if len(res.GetSketches()) != 2 {
t.Error("Expected len(res) == 2, got ", len(res.GetSketches()))
}
if _, err := client.DeleteSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
}
if _, err := client.Add(context.Background(), addReq); err == nil {
t.Error("Expected error, got", err)
}
if res, err := client.ListAll(context.Background(), &pb.Empty{}); err != nil {
t.Error("Did not expect error, got", err)
} else if len(res.GetSketches()) != 1 {
t.Error("Expected len(res) == 1, got ", len(res.GetSketches()))
}
}
示例6: TestNoSketches
func TestNoSketches(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
m := NewManager()
if sketches := m.GetSketches(); len(sketches) != 0 {
t.Error("Expected 0 sketches, got", len(sketches))
}
}
示例7: TestAddGetFreqSketch
func TestAddGetFreqSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
client, conn := setupClient()
defer tearDownClient(conn)
typ := pb.SketchType_FREQ
name := "yoyo"
in := &pb.Sketch{
Name: proto.String(name),
Type: &typ,
Properties: &pb.SketchProperties{
MaxUniqueItems: proto.Int64(1337), // FIXME: Allow default as -1
Size: proto.Int64(7),
},
}
if res, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
} else if res.GetName() != in.GetName() {
t.Errorf("Expected name == %s, got %s", in.GetName(), res.GetName())
} else if res.GetType() != in.GetType() {
t.Errorf("Expected name == %q, got %q", in.GetType(), res.GetType())
}
addReq := &pb.AddRequest{
Sketch: in,
Values: []string{"a", "a", "b", "c", "d"},
}
expected := map[string]int64{
"a": 2, "b": 1, "c": 1, "d": 1, "e": 0,
}
if _, err := client.Add(context.Background(), addReq); err != nil {
t.Error("Did not expect error, got", err)
}
getReq := &pb.GetRequest{
Sketches: []*pb.Sketch{in},
Values: []string{"a", "b", "c", "d", "e", "b"},
}
if res, err := client.GetFrequency(context.Background(), getReq); err != nil {
t.Error("Did not expect error, got", err)
} else {
for _, v := range res.GetResults()[0].GetFrequencies() {
if expected[v.GetValue()] != v.GetCount() {
t.Errorf("Expected %s == %d, got", v.GetValue(), v.GetCount())
}
}
}
}
示例8: TestAddBloom
func TestAddBloom(t *testing.T) {
testutils.SetupTests()
defer testutils.TearDownTests()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(1024)
info.Name = utils.Stringp("marvel")
sketch, err := NewBloomSketch(info)
if err != nil {
t.Error("expected avengers to have no error, got", err)
}
values := [][]byte{
[]byte("sabertooth"),
[]byte("thunderbolt"),
[]byte("havoc"),
[]byte("cyclops"),
[]byte("cyclops"),
[]byte("cyclops"),
[]byte("havoc")}
if _, err := sketch.Add(values); err != nil {
t.Error("expected no errors, got", err)
}
check := map[string]bool{
"sabertooth": true,
"thunderbolt": true,
"havoc": true,
"cyclops": true,
"wolverine": false,
"iceman": false,
"rogue": false,
"storm": false}
if res, err := sketch.Get(values); err != nil {
t.Error("expected no errors, got", err)
} else {
tmp := res.(*pb.MembershipResult)
mres := tmp.GetMemberships()
// FIXME: Flatten to avoid O(n^2) complexity
for key := range check {
for i := 0; i < len(mres); i++ {
if mres[i].GetValue() == key &&
mres[i].GetIsMember() != check[key] {
// FIXME: Use t.Errorf (using + is ugly)
t.Error("expected member == "+strconv.FormatBool(check[key])+", got", mres[i].GetIsMember())
}
}
}
}
}
示例9: setupClient
func setupClient() (pb.SkizzeClient, *grpc.ClientConn) {
testutils.SetupTests()
m := manager.NewManager()
datadir := config.DataDir
go Run(m, "127.0.0.1", 7777, datadir)
time.Sleep(time.Millisecond * 50)
// Connect to the server.
conn, err := grpc.Dial("127.0.0.1:7777", grpc.WithInsecure())
if err != nil {
logger.Criticalf("fail to dial: %v", err)
}
return pb.NewSkizzeClient(conn), conn
}
示例10: TestAddCMLThreshold
func TestAddCMLThreshold(t *testing.T) {
testutils.SetupTests()
defer testutils.TearDownTests()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(1024)
info.Name = utils.Stringp("marvel")
typ := pb.SketchType_FREQ
info.Type = &typ
sketch, err := NewCMLSketch(info)
if err != nil {
t.Error("expected avengers to have no error, got", err)
}
rValues := make(map[string]uint64)
var sValues [][]byte
thresholdSize := int64(sketch.threshold.size)
for i := int64(0); i < info.GetProperties().GetMaxUniqueItems()/10; i++ {
value := fmt.Sprintf("value-%d", i)
freq := uint64(rand.Int63()) % 100
values := make([][]byte, freq, freq)
for i := range values {
values[i] = []byte(value)
}
if _, err := sketch.Add(values); err != nil {
t.Error("expected no errors, got", err)
}
rValues[value] = freq
sValues = append(sValues, []byte(value))
// Threshold should be nil once more than 10% is filled
if sketch.threshold != nil && i >= thresholdSize {
t.Error("expected threshold == nil for i ==", i)
}
if res, err := sketch.Get(sValues); err != nil {
t.Error("expected no errors, got", err)
} else {
tmp := res.(*pb.FrequencyResult)
mres := tmp.GetFrequencies()
for i := 0; i < len(mres); i++ {
if key := mres[i].GetValue(); rValues[key] != uint64(mres[i].GetCount()) {
t.Fatalf("expected %s: %d, got %d", mres[i].GetValue(), rValues[key], uint64(mres[i].GetCount()))
}
}
}
}
}
示例11: TestAddGetCardSketch
func TestAddGetCardSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
client, conn := setupClient()
defer tearDownClient(conn)
typ := pb.SketchType_CARD
name := "yoyo"
in := &pb.Sketch{
Name: proto.String(name),
Type: &typ,
Properties: &pb.SketchProperties{
MaxUniqueItems: proto.Int64(1337), // FIXME: Allow default as -1
Size: proto.Int64(7),
},
}
if res, err := client.CreateSketch(context.Background(), in); err != nil {
t.Error("Did not expect error, got", err)
} else if res.GetName() != in.GetName() {
t.Errorf("Expected name == %s, got %s", in.GetName(), res.GetName())
} else if res.GetType() != in.GetType() {
t.Errorf("Expected name == %q, got %q", in.GetType(), res.GetType())
}
addReq := &pb.AddRequest{
Sketch: in,
Values: []string{"a", "b", "c", "d", "a", "b"},
}
if _, err := client.Add(context.Background(), addReq); err != nil {
t.Error("Did not expect error, got", err)
}
getReq := &pb.GetRequest{
Sketches: []*pb.Sketch{in},
Values: []string{},
}
if res, err := client.GetCardinality(context.Background(), getReq); err != nil {
t.Error("Did not expect error, got", err)
} else if res.GetResults()[0].GetCardinality() != 4 {
t.Error("Expected cardinality 4, got", res.GetResults()[0].GetCardinality())
}
}
示例12: TestCreateInvalidSketch
func TestCreateInvalidSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
m := NewManager()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(10000)
info.Name = utils.Stringp("avengers")
info.Type = nil
if err := m.CreateSketch(info); err == nil {
t.Error("Expected error invalid sketch, got", err)
}
if sketches := m.GetSketches(); len(sketches) != 0 {
t.Error("Expected 0 sketches, got", len(sketches))
}
}
示例13: TestAddHLLPPThreshold
func TestAddHLLPPThreshold(t *testing.T) {
testutils.SetupTests()
defer testutils.TearDownTests()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(1024)
info.Name = utils.Stringp("marvel")
typ := pb.SketchType_CARD
info.Type = &typ
sketch, err := NewHLLPPSketch(info)
if err != nil {
t.Error("expected avengers to have no error, got", err)
}
rValues := make(map[string]uint64)
thresholdSize := int64(sketch.threshold.size)
for i := int64(0); i < info.GetProperties().GetMaxUniqueItems()/10; i++ {
freq := uint64(rand.Int63()) % 100
value := fmt.Sprintf("value-%d", i)
values := make([][]byte, freq+1, freq+1)
for i := range values {
values[i] = []byte(value)
}
if _, err := sketch.Add(values); err != nil {
t.Error("expected no errors, got", err)
}
rValues[value] = freq
// Threshold should be nil once more than 10% is filled
if sketch.threshold != nil && i >= thresholdSize {
t.Error("expected threshold == nil for i ==", i)
}
if res, err := sketch.Get(nil); err != nil {
t.Error("expected no errors, got", err)
} else {
tmp := res.(*pb.CardinalityResult)
mres := tmp.GetCardinality()
if int64(len(rValues)) != mres {
t.Fatalf("expected cardinality %d, got %d", len(rValues), mres)
}
}
}
}
示例14: TestAddBloomThreshold
func TestAddBloomThreshold(t *testing.T) {
testutils.SetupTests()
defer testutils.TearDownTests()
info := datamodel.NewEmptyInfo()
info.Properties.MaxUniqueItems = utils.Int64p(1024)
info.Name = utils.Stringp("marvel")
sketch, err := NewBloomSketch(info)
if err != nil {
t.Error("expected avengers to have no error, got", err)
}
var rValues [][]byte
thresholdSize := int64(sketch.threshold.size)
for i := int64(0); i < info.GetProperties().GetMaxUniqueItems()/3; i++ {
value := fmt.Sprintf("value-%d", i)
values := [][]byte{
[]byte(value),
}
if _, err := sketch.Add(values); err != nil {
t.Error("expected no errors, got", err)
}
rValues = append(rValues, []byte(value))
// Threshold should be nil once more than 10% is filled
if sketch.threshold != nil && i >= thresholdSize {
t.Error("expected threshold == nil for i ==", i)
}
if res, err := sketch.Get(rValues); err != nil {
t.Error("expected no errors, got", err)
} else {
tmp := res.(*pb.MembershipResult)
mres := tmp.GetMemberships()
for i := 0; i < len(mres); i++ {
if !mres[i].GetIsMember() {
t.Fatalf("expected %s ==> member == true, got false", mres[i].GetValue())
break
}
}
}
}
}
示例15: TestDeleteNonExistingSketch
func TestDeleteNonExistingSketch(t *testing.T) {
config.Reset()
testutils.SetupTests()
defer testutils.TearDownTests()
m := NewManager()
info := datamodel.NewEmptyInfo()
typ := pb.SketchType_CARD
info.Properties.MaxUniqueItems = utils.Int64p(10000)
info.Name = utils.Stringp(fmt.Sprintf("marvel"))
info.Type = &typ
if err := m.DeleteSketch(info.ID()); err == nil {
t.Error("Expected errors deleting non-existing sketch, got", err)
}
if sketches := m.GetSketches(); len(sketches) != 0 {
t.Error("Expected 0 sketches, got", len(sketches))
}
}