Skip to content

Commit

Permalink
ci: run tests under private tenant to avoid applying permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Dec 19, 2023
1 parent d08380b commit d06c4f4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 50 deletions.
10 changes: 2 additions & 8 deletions api_chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,9 @@ func TestGetChatMembers(t *testing.T) {
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.NotEmpty(t, resp.Data.Items)
assert.NotEmpty(t, resp.Data.PageToken)
assert.Empty(t, resp.Data.PageToken)
assert.NotEmpty(t, resp.Data.MemberTotal)
if assert.True(t, resp.Data.HasMore) {
nextResp, err := bot.GetChatMembers(testGroupChatID, resp.Data.PageToken, 1)
if assert.NoError(t, err) {
assert.Equal(t, 0, nextResp.Code)
t.Log(nextResp.Data.Items)
}
}
assert.False(t, resp.Data.HasMore)
}
}

Expand Down
74 changes: 45 additions & 29 deletions api_group_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lark

import (
"fmt"
"testing"
"time"

Expand All @@ -17,54 +18,69 @@ func TestGetGroupList(t *testing.T) {
}

func TestGetGroupInfo(t *testing.T) {
resp, err := bot.GetGroupInfo("oc_51e1f7ff2b3dbe8f74b7b22d5d44d14e")
resp, err := bot.GetGroupInfo(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.Equal(t, "go-lark开发者交流群", resp.Data.Name)
assert.Equal(t, "go-lark-ci", resp.Data.Name)
assert.NotEmpty(t, resp.Data.Members)
}
}

func TestGroupCreateDisbandAddDelete(t *testing.T) {
createResp, err := bot.CreateGroup("go-lark-ci create-group", "group create", []string{testUserOpenID})
func TestGroupCRUD(t *testing.T) {
// create group
createResp, err := bot.CreateGroup(
fmt.Sprintf("go-lark-ci group %d", time.Now().Unix()),
"group create",
[]string{testUserOpenID},
)
if assert.NoError(t, err) {
assert.Equal(t, 0, createResp.Code)
t.Log(createResp.OpenChatID)
}

addResp, err := bot.AddGroupMember(createResp.OpenChatID, []string{"ou_b4852f3f88e454522180a5fcb346648d"})
groupChatID := createResp.OpenChatID
// delete member
delResp, err := bot.DeleteGroupMember(groupChatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, delResp.Code)
}
// add member
addResp, err := bot.AddGroupMember(groupChatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, addResp.Code)
}
delResp, err := bot.DeleteGroupMember(createResp.OpenChatID, []string{"ou_b4852f3f88e454522180a5fcb346648d"})
// delete again
delResp, err = bot.DeleteGroupMember(groupChatID, []string{testUserOpenID})
if assert.NoError(t, err) {
assert.Equal(t, 0, delResp.Code)
}
addV4Resp, err := bot.AddGroupMemberByUserID(testGroupChatID, []string{"55677932"})
// add by user id
addByUserResp, err := bot.AddGroupMemberByUserID(groupChatID, []string{testUserID})
if assert.NoError(t, err) {
assert.Equal(t, 0, addV4Resp.Code)
assert.Equal(t, 0, addByUserResp.Code)
}

disbandResp, err := bot.DisbandGroup(createResp.OpenChatID)
assert.Nil(t, err)
assert.Zero(t, disbandResp.Code)
}

func TestUpdateGroupInfo(t *testing.T) {
_, err := bot.UpdateGroupInfo(&UpdateGroupInfoReq{
OpenChatID: "oc_dae15ce1b55b00ecf853c50336a51e55",
// update info
updateResp, err := bot.UpdateGroupInfo(&UpdateGroupInfoReq{
OpenChatID: groupChatID,
Name: "test 1",
})
assert.Nil(t, err)
if assert.NoError(t, err) {
assert.Equal(t, 0, updateResp.Code)
}
// disband
disbandResp, err := bot.DisbandGroup(groupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, disbandResp.Code)
}
}

func TestAddRemoveBot(t *testing.T) {
openChatID := "oc_dae15ce1b55b00ecf853c50336a51e55"

_, err := bot.RemoveBotFromGroup(openChatID)
assert.Nil(t, err)
time.Sleep(time.Second)

_, err = bot.AddBotToGroup(openChatID)
assert.Nil(t, err)
func TestBotAddRemove(t *testing.T) {
// rm bot
rmBotResp, err := bot.RemoveBotFromGroup(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, rmBotResp.Code)
}
// add bot
addBotResp, err := bot.AddBotToGroup(testGroupChatID)
if assert.NoError(t, err) {
assert.Equal(t, 0, addBotResp.Code)
}
}
6 changes: 3 additions & 3 deletions api_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,21 @@ func TestPostMessage(t *testing.T) {
}
// file
msg = NewMsgBuffer(MsgFile)
om = msg.BindChatID(testGroupChatID).File("file_v2_356de203-39c2-49fd-8357-70b9b311f44g").Build()
om = msg.BindChatID(testGroupChatID).File("file_v3_0069_61085e72-3285-4ac8-82ec-31b060eeae7g").Build()
resp, err = bot.PostMessage(om)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.NotEmpty(t, resp.Data.MessageID)
}
// audio - not actually tested
msg = NewMsgBuffer(MsgAudio)
om = msg.BindChatID(testGroupChatID).File("file_v2_356de203-39c2-49fd-8357-70b9b311f44g").Build()
om = msg.BindChatID(testGroupChatID).File("file_v3_0069_61085e72-3285-4ac8-82ec-31b060eeae7g").Build()
resp, err = bot.PostMessage(om)
assert.NotEqual(t, 0, resp.Code)
assert.NotEmpty(t, resp.Msg)
// media - not actually tested
msg = NewMsgBuffer(MsgMedia)
om = msg.BindChatID(testGroupChatID).Media("file_v2_b53cd6cc-5327-4968-8bf6-4528deb3068g", "img_v2_b276195a-9ae0-4fec-bbfe-f74b4d5a994g").Build()
om = msg.BindChatID(testGroupChatID).Media("file_v3_0069_61085e72-3285-4ac8-82ec-31b060eeae7g", "img_v3_0269_ba0a83c6-21ff-48e2-a159-9061d2c8217g").Build()
resp, err = bot.PostMessage(om)
assert.NotEqual(t, 0, resp.Code)
assert.NotEmpty(t, resp.Msg)
Expand Down
1 change: 1 addition & 0 deletions api_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type PostNotificationV2Resp struct {
}

// PostNotification send message to a webhook
// deprecated: legacy version, please use PostNotificationV2 instead
func (bot *Bot) PostNotification(title, text string) (*PostNotificationResp, error) {
if !bot.requireType(NotificationBot) {
return nil, ErrBotTypeError
Expand Down
11 changes: 1 addition & 10 deletions api_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestWebhookV1(t *testing.T) {
bot := NewNotificationBot(testWebhookV1)
resp, err := bot.PostNotification("", "no title message")
assert.NoError(t, err)
assert.True(t, resp.Ok)
_, err = bot.PostNotification("go-lark CI", "it works")
assert.NoError(t, err)
}

// A weird case which sends V2 message body with V1 URL
func TestWebhookV1Error(t *testing.T) {
bot := NewNotificationBot(testWebhookV1)
Expand Down Expand Up @@ -92,7 +83,7 @@ func TestWebhookV2Signed(t *testing.T) {
bot := NewNotificationBot(testWebhookV2Signed)

mbText := NewMsgBuffer(MsgText)
mbText.Text("hello sign").WithSign("LIpnNexV7rwOyOebKoqSdb", time.Now().Unix())
mbText.Text("hello sign").WithSign("FT1dnAgPYYTcpafMTkhPjc", time.Now().Unix())
resp, err := bot.PostNotificationV2(mbText.Build())
assert.NoError(t, err)
assert.Zero(t, resp.StatusCode)
Expand Down

0 comments on commit d06c4f4

Please sign in to comment.