From 815df3188d1d72e9c7b57f560f0c5562a8f66462 Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Thu, 15 Feb 2024 20:35:01 +0800 Subject: [PATCH] Add more tests --- session_pool_test.go | 54 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/session_pool_test.go b/session_pool_test.go index 85c5fbb5..53b59d50 100644 --- a/session_pool_test.go +++ b/session_pool_test.go @@ -522,14 +522,14 @@ func TestSessionPoolApplyTag(t *testing.T) { t.Fatal(err) } assert.Equal(t, 1, len(tags)) - assert.Equal(t, "account", tags[0].Name, "tag name should be account") + assert.Equal(t, "account", tags[0].Name) labels, err := sessionPool.DescTag("account") if err != nil { t.Fatal(err) } assert.Equal(t, 1, len(labels)) - assert.Equal(t, "name", labels[0].Field, "field name should be name") - assert.Equal(t, "string", labels[0].Type, "field type should be string") + assert.Equal(t, "name", labels[0].Field) + assert.Equal(t, "string", labels[0].Type) tagSchema = LabelSchema{ Name: "account", @@ -560,18 +560,52 @@ func TestSessionPoolApplyTag(t *testing.T) { t.Fatal(err) } assert.Equal(t, 1, len(tags)) - assert.Equal(t, "account", tags[0].Name, "tag name should be account") + assert.Equal(t, "account", tags[0].Name) labels, err = sessionPool.DescTag("account") if err != nil { t.Fatal(err) } assert.Equal(t, 3, len(labels)) - assert.Equal(t, "name", labels[0].Field, "field name should be name") - assert.Equal(t, "string", labels[0].Type, "field type should be string") - assert.Equal(t, "email", labels[1].Field, "field name should be email") - assert.Equal(t, "string", labels[1].Type, "field type should be string") - assert.Equal(t, "phone", labels[2].Field, "field name should be phone") - assert.Equal(t, "int64", labels[2].Type, "field type should be int64") + assert.Equal(t, "name", labels[0].Field) + assert.Equal(t, "string", labels[0].Type) + assert.Equal(t, "email", labels[1].Field) + assert.Equal(t, "string", labels[1].Type) + assert.Equal(t, "phone", labels[2].Field) + assert.Equal(t, "int64", labels[2].Type) + tagSchema = LabelSchema{ + Name: "account", + Fields: []LabelFieldSchema{ + { + Field: "name", + Type: "string", + Nullable: false, + }, + { + Field: "phone", + Type: "int64", + Nullable: true, + }, + }, + } + _, err = sessionPool.ApplyTag(tagSchema) + if err != nil { + t.Fatal(err) + } + tags, err = sessionPool.ShowTags() + if err != nil { + t.Fatal(err) + } + assert.Equal(t, 1, len(tags)) + assert.Equal(t, "account", tags[0].Name) + labels, err = sessionPool.DescTag("account") + if err != nil { + t.Fatal(err) + } + assert.Equal(t, 2, len(labels)) + assert.Equal(t, "name", labels[0].Field) + assert.Equal(t, "string", labels[0].Type) + assert.Equal(t, "phone", labels[1].Field) + assert.Equal(t, "int64", labels[1].Type) } func TestIdleSessionCleaner(t *testing.T) {