コード例 #1
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestSimpleMessage(t *testing.T) {
	message, err := unmarshalMessage(simpleMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "C2147483705", message.Channel)
	assert.Equal(t, "U2147483697", message.User)
	assert.Equal(t, "Hello world", message.Text)
	assert.Equal(t, "1355517523.000005", message.Timestamp)
}
コード例 #2
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestGroupLeaveMessage(t *testing.T) {
	message, err := unmarshalMessage(groupLeaveMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "group_leave", message.SubType)
	assert.Equal(t, "1358877455.000010", message.Timestamp)
	assert.Equal(t, "U2147483828", message.User)
	assert.Equal(t, "<@U2147483828|cal> has left the group", message.Text)
}
コード例 #3
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestGroupUnarchiveMessage(t *testing.T) {
	message, err := unmarshalMessage(groupUnarchiveMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "group_unarchive", message.SubType)
	assert.Equal(t, "1361482916.000003", message.Timestamp)
	assert.Equal(t, "<U1234|@cal> un-archived the group", message.Text)
	assert.Equal(t, "U1234", message.User)
}
コード例 #4
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestGroupJoinMessage(t *testing.T) {
	message, err := unmarshalMessage(groupJoinMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "group_join", message.SubType)
	assert.Equal(t, "1358877458.000011", message.Timestamp)
	assert.Equal(t, "U2147483828", message.User)
	assert.Equal(t, "<@U2147483828|cal> has joined the group", message.Text)
}
コード例 #5
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestMessageDeletedMessage(t *testing.T) {
	message, err := unmarshalMessage(messageDeletedMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "message_deleted", message.SubType)
	assert.True(t, message.Hidden)
	assert.Equal(t, "C2147483705", message.Channel)
	assert.Equal(t, "1358878755.000001", message.Timestamp)
	assert.Equal(t, "1358878749.000002", message.DeletedTimestamp)
}
コード例 #6
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestPost(t *testing.T) {
	message, err := unmarshalMessage(testPost)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "file_share", message.SubType)
	assert.Equal(t, "<@U2147483697|tester> shared a file: <https://test.slack.com/files/tester/abc/test_post|test post>", message.Text)
	// TODO: Assert File
	assert.Equal(t, "U2147483697", message.User)
	assert.False(t, message.Upload)
	assert.Equal(t, "1433315416.000008", message.Timestamp)
}
コード例 #7
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestComment(t *testing.T) {
	message, err := unmarshalMessage(testComment)
	fmt.Println(err)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "file_comment", message.SubType)
	assert.Equal(t, "<@U2147483697|tester> commented on <@U2147483697|tester>'s file <https://test.slack.com/files/tester/abc/test_post|test post>: another comment", message.Text)
	// TODO: Assert File
	// TODO: Assert Comment
	assert.Equal(t, "1433316360.000009", message.Timestamp)
}
コード例 #8
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestUploadedFile(t *testing.T) {
	message, err := unmarshalMessage(uploadedFile)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "file_share", message.SubType)
	assert.Equal(t, "<@U2147483697|tester> uploaded a file: <https://test.slack.com/files/tester/abc/test.txt|test.txt> and commented: test comment here", message.Text)
	// TODO: Assert File
	assert.Equal(t, "U2147483697", message.User)
	assert.True(t, message.Upload)
	assert.Equal(t, "1433314757.000006", message.Timestamp)
}
コード例 #9
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestFileShareMessage(t *testing.T) {
	message, err := unmarshalMessage(fileShareMessage)
	fmt.Println(err)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "file_share", message.SubType)
	assert.Equal(t, "1358877455.000010", message.Timestamp)
	assert.Equal(t, "<@cal> uploaded a file: <https:...7.png|7.png>", message.Text)
	assert.Equal(t, "U2147483697", message.User)
	assert.True(t, message.Upload)
	assert.NotNil(t, message.File)
}
コード例 #10
0
func assertSimpleGroup(t *testing.T, group *Group) {
	assert.NotNil(t, group)
	assert.Equal(t, "G024BE91L", group.ID)
	assert.Equal(t, "secretplans", group.Name)
	assert.Equal(t, true, group.IsGroup)
	assert.Equal(t, JSONTime(1360782804), group.Created)
	assert.Equal(t, "U024BE7LH", group.Creator)
	assert.Equal(t, false, group.IsArchived)
	assert.Equal(t, "1401383885.000061", group.LastRead)
	assert.Equal(t, 0, group.UnreadCount)
	assert.Equal(t, 0, group.UnreadCountDisplay)
}
コード例 #11
0
ファイル: stars_test.go プロジェクト: bfontaine/stargazer
func TestStarNotification(t *testing.T) {
	s := Star{
		Added:     true,
		User:      "******",
		Timestamp: "1401",
		Message: Message{
			User:      "******",
			Channel:   "C123",
			Text:      "yo",
			Timestamp: "1400",
		},
	}

	slackInfo = &slack.Info{
		Team: &slack.Team{
			Name:   "yolo",
			Domain: "yoloo",
		},
	}

	n, err := s.notification()
	assert.Nil(t, err)

	assert.Equal(t,
		"@usernameU123 just starred your message in #channelC123: https://yoloo.slack.com/archives/channelC123/p1400",
		n)
}
コード例 #12
0
func TestMemoizeGetter(t *testing.T) {
	var calls int

	f := func(s string) (string, error) {
		calls++
		if s == "error" {
			return "", errors.New("oops")
		}
		return "called:" + s, nil
	}

	memoized := memoizeGetter(f)

	require.NotNil(t, memoized)
	assert.Equal(t, 0, calls)

	s, err := memoized("yo")
	assert.Nil(t, err)
	assert.Equal(t, "called:yo", s)
	assert.Equal(t, 1, calls)

	s, err = memoized("yo")
	assert.Nil(t, err)
	assert.Equal(t, "called:yo", s)
	assert.Equal(t, 1, calls)

	s, err = memoized("error")
	assert.NotNil(t, err)
	assert.Equal(t, 2, calls)

	s, err = memoized("error")
	assert.NotNil(t, err)
	assert.Equal(t, 3, calls)
}
コード例 #13
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestMessageChangedMessage(t *testing.T) {
	message, err := unmarshalMessage(messageChangedMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "message_changed", message.SubType)
	assert.True(t, message.Hidden)
	assert.Equal(t, "C2147483705", message.Channel)
	assert.NotNil(t, message.SubMessage)
	assert.Equal(t, "message", message.SubMessage.Type)
	assert.Equal(t, "U2147483697", message.SubMessage.User)
	assert.Equal(t, "Hello, world!", message.SubMessage.Text)
	assert.Equal(t, "1355517523.000005", message.SubMessage.Timestamp)
	assert.NotNil(t, message.SubMessage.Edited)
	assert.Equal(t, "U2147483697", message.SubMessage.Edited.User)
	assert.Equal(t, "1358878755.000001", message.SubMessage.Edited.Timestamp)
	assert.Equal(t, "1358878755.000001", message.Timestamp)
}
コード例 #14
0
func assertSimpleIM(t *testing.T, im *IM) {
	assert.NotNil(t, im)
	assert.Equal(t, "D024BFF1M", im.ID)
	assert.Equal(t, true, im.IsIM)
	assert.Equal(t, JSONTime(1360782804), im.Created)
	assert.Equal(t, false, im.IsUserDeleted)
	assert.Equal(t, true, im.IsOpen)
	assert.Equal(t, "1401383885.000061", im.LastRead)
	assert.Equal(t, 0, im.UnreadCount)
	assert.Equal(t, 0, im.UnreadCountDisplay)
}
コード例 #15
0
ファイル: main_test.go プロジェクト: bfontaine/stargazer
func TestGotDM(t *testing.T) {
	assert.Equal(t, enablingMessage, gotDM("d123", "u1", "enable"))
	assert.Equal(t, enablingMessage, gotDM("d123", "u2", "enable"))
	assert.Equal(t, enabledMessage, gotDM("d123", "u1", "enable"))

	assert.Equal(t, disabledMessage, gotDM("d123", "u3", "disable"))
	assert.Equal(t, disablingMessage, gotDM("d123", "u1", "disable"))
	assert.Equal(t, disabledMessage, gotDM("d123", "u1", "disable"))

	assert.Equal(t, "", gotDM("d123", "u4", "hello who are you"))
}
コード例 #16
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestGroupNameMessage(t *testing.T) {
	message, err := unmarshalMessage(groupNameMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "group_name", message.SubType)
	assert.Equal(t, "1358877455.000010", message.Timestamp)
	assert.Equal(t, "U2147483828", message.User)
	assert.Equal(t, "random", message.OldName)
	assert.Equal(t, "watercooler", message.Name)
	assert.Equal(t, "<@U2147483828|cal> has renamed the group from \"random\" to \"watercooler\"", message.Text)
}
コード例 #17
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestGroupTopicMessage(t *testing.T) {
	message, err := unmarshalMessage(groupTopicMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "group_topic", message.SubType)
	assert.Equal(t, "1358877455.000010", message.Timestamp)
	assert.Equal(t, "U2147483828", message.User)
	assert.Equal(t, "hello world", message.Topic)
	assert.Equal(t, "<@U2147483828|cal> set the group topic: hello world", message.Text)
}
コード例 #18
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestMeMessage(t *testing.T) {
	message, err := unmarshalMessage(meMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "me_message", message.SubType)
	assert.Equal(t, "C2147483705", message.Channel)
	assert.Equal(t, "U2147483697", message.User)
	assert.Equal(t, "is doing that thing", message.Text)
	assert.Equal(t, "1355517523.000005", message.Timestamp)
}
コード例 #19
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestChannelJoinInvitedMessage(t *testing.T) {
	message, err := unmarshalMessage(channelJoinInvitedMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "channel_join", message.SubType)
	assert.Equal(t, "1358877458.000011", message.Timestamp)
	assert.Equal(t, "U2147483828", message.User)
	assert.Equal(t, "<@U2147483828|cal> has joined the channel", message.Text)
	assert.Equal(t, "U2147483829", message.Inviter)
}
コード例 #20
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestGroupPurposeMessage(t *testing.T) {
	message, err := unmarshalMessage(groupPurposeMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "group_purpose", message.SubType)
	assert.Equal(t, "1358877455.000010", message.Timestamp)
	assert.Equal(t, "U2147483828", message.User)
	assert.Equal(t, "whatever", message.Purpose)
	assert.Equal(t, "<@U2147483828|cal> set the group purpose: whatever", message.Text)
}
コード例 #21
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestStarredMessage(t *testing.T) {
	message, err := unmarshalMessage(starredMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "is testing", message.Text)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "me_message", message.SubType)
	assert.Equal(t, "U2147483697", message.User)
	assert.Equal(t, "1433314126.000003", message.Timestamp)
	assert.Equal(t, true, message.IsStarred)
}
コード例 #22
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestEditedMessage(t *testing.T) {
	message, err := unmarshalMessage(editedMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "U2147483697", message.User)
	assert.Equal(t, "hello edited", message.Text)
	assert.NotNil(t, message.Edited)
	assert.Equal(t, "U2147483697", message.Edited.User)
	assert.Equal(t, "1433314416.000000", message.Edited.Timestamp)
	assert.Equal(t, "1433314408.000004", message.Timestamp)
}
コード例 #23
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestChannelArchiveMessage(t *testing.T) {
	message, err := unmarshalMessage(channelArchiveMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "channel_archive", message.SubType)
	assert.Equal(t, "1361482916.000003", message.Timestamp)
	assert.Equal(t, "<U1234|@cal> archived the channel", message.Text)
	assert.Equal(t, "U1234", message.User)
	assert.NotNil(t, message.Members)
	assert.Equal(t, 2, len(message.Members))
}
コード例 #24
0
ファイル: messages_test.go プロジェクト: bfontaine/stargazer
func TestBotMessage(t *testing.T) {
	message, err := unmarshalMessage(botMessage)
	assert.Nil(t, err)
	assert.NotNil(t, message)
	assert.Equal(t, "message", message.Type)
	assert.Equal(t, "bot_message", message.SubType)
	assert.Equal(t, "1358877455.000010", message.Timestamp)
	assert.Equal(t, "Pushing is the answer", message.Text)
	assert.Equal(t, "BB12033", message.BotID)
	assert.Equal(t, "github", message.Username)
	assert.NotNil(t, message.Icons)
	assert.Empty(t, message.Icons.IconURL)
	assert.Empty(t, message.Icons.IconEmoji)
}
コード例 #25
0
func assertSimpleChannel(t *testing.T, channel *Channel) {
	assert.NotNil(t, channel)
	assert.Equal(t, "C024BE91L", channel.ID)
	assert.Equal(t, "fun", channel.Name)
	assert.Equal(t, true, channel.IsChannel)
	assert.Equal(t, JSONTime(1360782804), channel.Created)
	assert.Equal(t, "U024BE7LH", channel.Creator)
	assert.Equal(t, false, channel.IsArchived)
	assert.Equal(t, false, channel.IsGeneral)
	assert.Equal(t, true, channel.IsMember)
	assert.Equal(t, "1401383885.000061", channel.LastRead)
	assert.Equal(t, 0, channel.UnreadCount)
	assert.Equal(t, 0, channel.UnreadCountDisplay)
}
コード例 #26
0
ファイル: requirements.go プロジェクト: bfontaine/stargazer
// Equal asserts that two objects are equal.
//
//    require.Equal(t, 123, 123, "123 and 123 should be equal")
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) {
	if !assert.Equal(t, expected, actual, msgAndArgs...) {
		t.FailNow()
	}
}