mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
more golint cleanup
This commit is contained in:
parent
800b0bce27
commit
99a92a0534
@ -15,21 +15,22 @@ import (
|
|||||||
|
|
||||||
const testTimeout = 5
|
const testTimeout = 5
|
||||||
|
|
||||||
type TestCondition struct {
|
type testCondition struct {
|
||||||
check func(*TestApp) bool
|
check func(*TestApp) bool
|
||||||
channel chan bool
|
channel chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestTopic struct {
|
type testTopic struct {
|
||||||
topic Topic
|
topic Topic
|
||||||
tags map[string]*Tag
|
tags map[string]*Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestChannel struct {
|
type testChannel struct {
|
||||||
channel Channel
|
channel Channel
|
||||||
topics map[string]*TestTopic
|
topics map[string]*testTopic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TestContactData holds contact data for a test
|
||||||
type TestContactData struct {
|
type TestContactData struct {
|
||||||
token string
|
token string
|
||||||
card Card
|
card Card
|
||||||
@ -40,26 +41,24 @@ type TestContactData struct {
|
|||||||
cardDetailRevision int64
|
cardDetailRevision int64
|
||||||
cardProfileRevision int64
|
cardProfileRevision int64
|
||||||
articles map[string]*Article
|
articles map[string]*Article
|
||||||
channels map[string]*TestChannel
|
channels map[string]*testChannel
|
||||||
offsync bool
|
offsync bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContact() (err error) {
|
func (c *TestContactData) updateContact() (err error) {
|
||||||
|
|
||||||
if c.cardDetailRevision != c.card.Data.DetailRevision {
|
if c.cardDetailRevision != c.card.Data.DetailRevision {
|
||||||
if err = c.UpdateContactCardDetail(); err != nil {
|
if err = c.updateContactCardDetail(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
c.cardDetailRevision = c.card.Data.DetailRevision
|
|
||||||
}
|
}
|
||||||
|
c.cardDetailRevision = c.card.Data.DetailRevision
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.cardProfileRevision != c.card.Data.ProfileRevision {
|
if c.cardProfileRevision != c.card.Data.ProfileRevision {
|
||||||
if err = c.UpdateContactCardProfile(); err != nil {
|
if err = c.updateContactCardProfile(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
c.cardProfileRevision = c.card.Data.ProfileRevision
|
|
||||||
}
|
}
|
||||||
|
c.cardProfileRevision = c.card.Data.ProfileRevision
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync rest only if connected
|
// sync rest only if connected
|
||||||
@ -68,45 +67,41 @@ func (c *TestContactData) UpdateContact() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.profileRevision != c.card.Data.NotifiedProfile {
|
if c.profileRevision != c.card.Data.NotifiedProfile {
|
||||||
if err = c.UpdateContactProfile(); err != nil {
|
if err = c.updateContactProfile(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
c.profileRevision = c.card.Data.NotifiedProfile
|
|
||||||
}
|
}
|
||||||
|
c.profileRevision = c.card.Data.NotifiedProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.viewRevision != c.card.Data.NotifiedView {
|
if c.viewRevision != c.card.Data.NotifiedView {
|
||||||
if err = c.UpdateContactArticle(); err != nil {
|
if err = c.updateContactArticle(); err != nil {
|
||||||
return
|
return
|
||||||
} else if err = c.UpdateContactChannels(); err != nil {
|
} else if err = c.updateContactChannels(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
c.articleRevision = c.card.Data.NotifiedArticle
|
c.articleRevision = c.card.Data.NotifiedArticle
|
||||||
c.channelRevision = c.card.Data.NotifiedChannel
|
c.channelRevision = c.card.Data.NotifiedChannel
|
||||||
c.viewRevision = c.card.Data.NotifiedView
|
c.viewRevision = c.card.Data.NotifiedView
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if c.articleRevision != c.card.Data.NotifiedArticle {
|
if c.articleRevision != c.card.Data.NotifiedArticle {
|
||||||
if err = c.UpdateContactArticle(); err != nil {
|
if err = c.updateContactArticle(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
c.articleRevision = c.card.Data.NotifiedArticle
|
|
||||||
}
|
}
|
||||||
|
c.articleRevision = c.card.Data.NotifiedArticle
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.channelRevision != c.card.Data.NotifiedChannel {
|
if c.channelRevision != c.card.Data.NotifiedChannel {
|
||||||
if err = c.UpdateContactChannels(); err != nil {
|
if err = c.updateContactChannels(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
c.channelRevision = c.card.Data.NotifiedChannel
|
|
||||||
}
|
}
|
||||||
|
c.channelRevision = c.card.Data.NotifiedChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactProfile() (err error) {
|
func (c *TestContactData) updateContactProfile() (err error) {
|
||||||
var msg DataMessage
|
var msg DataMessage
|
||||||
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
||||||
params := &TestAPIParams{query: "/profile/message", tokenType: APPTokenContact, token: token}
|
params := &TestAPIParams{query: "/profile/message", tokenType: APPTokenContact, token: token}
|
||||||
@ -123,7 +118,7 @@ func (c *TestContactData) UpdateContactProfile() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactArticle() (err error) {
|
func (c *TestContactData) updateContactArticle() (err error) {
|
||||||
var articles []Article
|
var articles []Article
|
||||||
if c.articleRevision == 0 || c.viewRevision != c.card.Data.NotifiedView {
|
if c.articleRevision == 0 || c.viewRevision != c.card.Data.NotifiedView {
|
||||||
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
||||||
@ -154,7 +149,7 @@ func (c *TestContactData) UpdateContactArticle() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactChannels() (err error) {
|
func (c *TestContactData) updateContactChannels() (err error) {
|
||||||
var channels []Channel
|
var channels []Channel
|
||||||
if c.channelRevision == 0 || c.viewRevision != c.card.Data.NotifiedView {
|
if c.channelRevision == 0 || c.viewRevision != c.card.Data.NotifiedView {
|
||||||
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
||||||
@ -182,15 +177,15 @@ func (c *TestContactData) UpdateContactChannels() (err error) {
|
|||||||
tc, set := c.channels[channel.ID]
|
tc, set := c.channels[channel.ID]
|
||||||
if set {
|
if set {
|
||||||
if channel.Revision != tc.channel.Revision {
|
if channel.Revision != tc.channel.Revision {
|
||||||
if err = c.UpdateContactChannel(tc, &channel); err != nil {
|
if err = c.updateContactChannel(tc, &channel); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tc.channel.Revision = channel.Revision
|
tc.channel.Revision = channel.Revision
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tc := &TestChannel{channel: Channel{ID: channel.ID, Data: &ChannelData{}}}
|
tc := &testChannel{channel: Channel{ID: channel.ID, Data: &ChannelData{}}}
|
||||||
c.channels[channel.ID] = tc
|
c.channels[channel.ID] = tc
|
||||||
if err = c.UpdateContactChannel(tc, &channel); err != nil {
|
if err = c.updateContactChannel(tc, &channel); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tc.channel.Revision = channel.Revision
|
tc.channel.Revision = channel.Revision
|
||||||
@ -200,10 +195,10 @@ func (c *TestContactData) UpdateContactChannels() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactChannel(storeChannel *TestChannel, channel *Channel) (err error) {
|
func (c *TestContactData) updateContactChannel(storeChannel *testChannel, channel *Channel) (err error) {
|
||||||
if storeChannel.channel.Revision != channel.Revision {
|
if storeChannel.channel.Revision != channel.Revision {
|
||||||
if storeChannel.channel.Data.TopicRevision != channel.Data.TopicRevision {
|
if storeChannel.channel.Data.TopicRevision != channel.Data.TopicRevision {
|
||||||
if err = c.UpdateContactChannelTopics(storeChannel); err != nil {
|
if err = c.updateContactChannelTopics(storeChannel); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
storeChannel.channel.Data.TopicRevision = channel.Data.TopicRevision
|
storeChannel.channel.Data.TopicRevision = channel.Data.TopicRevision
|
||||||
@ -231,7 +226,7 @@ func (c *TestContactData) UpdateContactChannel(storeChannel *TestChannel, channe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactChannelTopics(storeChannel *TestChannel) (err error) {
|
func (c *TestContactData) updateContactChannelTopics(storeChannel *testChannel) (err error) {
|
||||||
var topics []Topic
|
var topics []Topic
|
||||||
if storeChannel.channel.Revision == 0 {
|
if storeChannel.channel.Revision == 0 {
|
||||||
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
||||||
@ -241,7 +236,7 @@ func (c *TestContactData) UpdateContactChannelTopics(storeChannel *TestChannel)
|
|||||||
if err = TestAPIRequest(GetChannelTopics, params, response); err != nil {
|
if err = TestAPIRequest(GetChannelTopics, params, response); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
storeChannel.topics = make(map[string]*TestTopic)
|
storeChannel.topics = make(map[string]*testTopic)
|
||||||
} else {
|
} else {
|
||||||
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
||||||
revision := strconv.FormatInt(storeChannel.channel.Revision, 10)
|
revision := strconv.FormatInt(storeChannel.channel.Revision, 10)
|
||||||
@ -260,15 +255,15 @@ func (c *TestContactData) UpdateContactChannelTopics(storeChannel *TestChannel)
|
|||||||
storeTopic, set := storeChannel.topics[topic.ID]
|
storeTopic, set := storeChannel.topics[topic.ID]
|
||||||
if set {
|
if set {
|
||||||
if topic.Revision != storeTopic.topic.Revision {
|
if topic.Revision != storeTopic.topic.Revision {
|
||||||
if err = c.UpdateContactChannelTopic(storeChannel, storeTopic, &topic); err != nil {
|
if err = c.updateContactChannelTopic(storeChannel, storeTopic, &topic); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
storeTopic.topic.Revision = topic.Revision
|
storeTopic.topic.Revision = topic.Revision
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storeTopic := &TestTopic{topic: Topic{ID: topic.ID, Data: &TopicData{}}}
|
storeTopic := &testTopic{topic: Topic{ID: topic.ID, Data: &TopicData{}}}
|
||||||
storeChannel.topics[topic.ID] = storeTopic
|
storeChannel.topics[topic.ID] = storeTopic
|
||||||
if err = c.UpdateContactChannelTopic(storeChannel, storeTopic, &topic); err != nil {
|
if err = c.updateContactChannelTopic(storeChannel, storeTopic, &topic); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
storeTopic.topic.Revision = topic.Revision
|
storeTopic.topic.Revision = topic.Revision
|
||||||
@ -278,10 +273,10 @@ func (c *TestContactData) UpdateContactChannelTopics(storeChannel *TestChannel)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactChannelTopic(storeChannel *TestChannel, storeTopic *TestTopic, topic *Topic) (err error) {
|
func (c *TestContactData) updateContactChannelTopic(storeChannel *testChannel, storeTopic *testTopic, topic *Topic) (err error) {
|
||||||
if storeTopic.topic.Revision != topic.Revision {
|
if storeTopic.topic.Revision != topic.Revision {
|
||||||
if storeTopic.topic.Data.TagRevision != topic.Data.TagRevision {
|
if storeTopic.topic.Data.TagRevision != topic.Data.TagRevision {
|
||||||
if err = c.UpdateContactChannelTopicTags(storeChannel, storeTopic); err != nil {
|
if err = c.updateContactChannelTopicTags(storeChannel, storeTopic); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
storeTopic.topic.Data.TagRevision = topic.Data.TagRevision
|
storeTopic.topic.Data.TagRevision = topic.Data.TagRevision
|
||||||
@ -310,7 +305,7 @@ func (c *TestContactData) UpdateContactChannelTopic(storeChannel *TestChannel, s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactChannelTopicTags(storeChannel *TestChannel, storeTopic *TestTopic) (err error) {
|
func (c *TestContactData) updateContactChannelTopicTags(storeChannel *testChannel, storeTopic *testTopic) (err error) {
|
||||||
var tags []Tag
|
var tags []Tag
|
||||||
if storeTopic.topic.Revision == 0 {
|
if storeTopic.topic.Revision == 0 {
|
||||||
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.GUID + "." + c.card.Data.CardDetail.Token
|
||||||
@ -344,7 +339,7 @@ func (c *TestContactData) UpdateContactChannelTopicTags(storeChannel *TestChanne
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactCardDetail() (err error) {
|
func (c *TestContactData) updateContactCardDetail() (err error) {
|
||||||
var cardDetail CardDetail
|
var cardDetail CardDetail
|
||||||
params := &TestAPIParams{query: "/contact/cards/{cardID}/detail", tokenType: APPTokenAgent, token: c.token,
|
params := &TestAPIParams{query: "/contact/cards/{cardID}/detail", tokenType: APPTokenAgent, token: c.token,
|
||||||
path: map[string]string{"cardID": c.card.ID}}
|
path: map[string]string{"cardID": c.card.ID}}
|
||||||
@ -356,7 +351,7 @@ func (c *TestContactData) UpdateContactCardDetail() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactCardProfile() (err error) {
|
func (c *TestContactData) updateContactCardProfile() (err error) {
|
||||||
var cardProfile CardProfile
|
var cardProfile CardProfile
|
||||||
params := &TestAPIParams{query: "/contact/cards/{cardID}/profile", tokenType: APPTokenAgent, token: c.token,
|
params := &TestAPIParams{query: "/contact/cards/{cardID}/profile", tokenType: APPTokenAgent, token: c.token,
|
||||||
path: map[string]string{"cardID": c.card.ID}}
|
path: map[string]string{"cardID": c.card.ID}}
|
||||||
@ -368,28 +363,30 @@ func (c *TestContactData) UpdateContactCardProfile() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NewTestApp allocate a new TestApp structure
|
||||||
func NewTestApp() *TestApp {
|
func NewTestApp() *TestApp {
|
||||||
return &TestApp{
|
return &TestApp{
|
||||||
groups: make(map[string]*Group),
|
groups: make(map[string]*Group),
|
||||||
articles: make(map[string]*Article),
|
articles: make(map[string]*Article),
|
||||||
channels: make(map[string]*TestChannel),
|
channels: make(map[string]*testChannel),
|
||||||
contacts: make(map[string]*TestContactData),
|
contacts: make(map[string]*TestContactData),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TestApp holds an instance of test app use case
|
||||||
type TestApp struct {
|
type TestApp struct {
|
||||||
name string
|
name string
|
||||||
revision Revision
|
revision Revision
|
||||||
profile Profile
|
profile Profile
|
||||||
groups map[string]*Group
|
groups map[string]*Group
|
||||||
articles map[string]*Article
|
articles map[string]*Article
|
||||||
channels map[string]*TestChannel
|
channels map[string]*testChannel
|
||||||
contacts map[string]*TestContactData
|
contacts map[string]*TestContactData
|
||||||
|
|
||||||
token string
|
token string
|
||||||
|
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
condition *TestCondition
|
condition *testCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) updateProfile() (err error) {
|
func (a *TestApp) updateProfile() (err error) {
|
||||||
@ -481,7 +478,7 @@ func (a *TestApp) updateChannels() (err error) {
|
|||||||
storeChannel.channel.Revision = channel.Revision
|
storeChannel.channel.Revision = channel.Revision
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storeChannel := &TestChannel{channel: Channel{ID: channel.ID, Data: &ChannelData{}}}
|
storeChannel := &testChannel{channel: Channel{ID: channel.ID, Data: &ChannelData{}}}
|
||||||
a.channels[channel.ID] = storeChannel
|
a.channels[channel.ID] = storeChannel
|
||||||
if err = a.updateChannel(storeChannel, &channel); err != nil {
|
if err = a.updateChannel(storeChannel, &channel); err != nil {
|
||||||
return
|
return
|
||||||
@ -493,7 +490,7 @@ func (a *TestApp) updateChannels() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) updateChannel(storeChannel *TestChannel, channel *Channel) (err error) {
|
func (a *TestApp) updateChannel(storeChannel *testChannel, channel *Channel) (err error) {
|
||||||
if storeChannel.channel.Revision != channel.Revision {
|
if storeChannel.channel.Revision != channel.Revision {
|
||||||
if storeChannel.channel.Data.TopicRevision != channel.Data.TopicRevision {
|
if storeChannel.channel.Data.TopicRevision != channel.Data.TopicRevision {
|
||||||
if err = a.updateChannelTopics(storeChannel); err != nil {
|
if err = a.updateChannelTopics(storeChannel); err != nil {
|
||||||
@ -523,7 +520,7 @@ func (a *TestApp) updateChannel(storeChannel *TestChannel, channel *Channel) (er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) updateChannelTopics(storeChannel *TestChannel) (err error) {
|
func (a *TestApp) updateChannelTopics(storeChannel *testChannel) (err error) {
|
||||||
var topics []Topic
|
var topics []Topic
|
||||||
if storeChannel.channel.Revision == 0 {
|
if storeChannel.channel.Revision == 0 {
|
||||||
params := &TestAPIParams{query: "/channels/{channelID}/topics",
|
params := &TestAPIParams{query: "/channels/{channelID}/topics",
|
||||||
@ -532,7 +529,7 @@ func (a *TestApp) updateChannelTopics(storeChannel *TestChannel) (err error) {
|
|||||||
if err = TestAPIRequest(GetChannelTopics, params, response); err != nil {
|
if err = TestAPIRequest(GetChannelTopics, params, response); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
storeChannel.topics = make(map[string]*TestTopic)
|
storeChannel.topics = make(map[string]*testTopic)
|
||||||
} else {
|
} else {
|
||||||
revision := strconv.FormatInt(storeChannel.channel.Revision, 10)
|
revision := strconv.FormatInt(storeChannel.channel.Revision, 10)
|
||||||
params := &TestAPIParams{query: "/channels/{channelID}/topics?revision=" + revision,
|
params := &TestAPIParams{query: "/channels/{channelID}/topics?revision=" + revision,
|
||||||
@ -556,7 +553,7 @@ func (a *TestApp) updateChannelTopics(storeChannel *TestChannel) (err error) {
|
|||||||
storeTopic.topic.Revision = topic.Revision
|
storeTopic.topic.Revision = topic.Revision
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storeTopic := &TestTopic{topic: Topic{ID: topic.ID, Data: &TopicData{}}}
|
storeTopic := &testTopic{topic: Topic{ID: topic.ID, Data: &TopicData{}}}
|
||||||
storeChannel.topics[topic.ID] = storeTopic
|
storeChannel.topics[topic.ID] = storeTopic
|
||||||
if err = a.updateChannelTopic(storeChannel, storeTopic, &topic); err != nil {
|
if err = a.updateChannelTopic(storeChannel, storeTopic, &topic); err != nil {
|
||||||
return
|
return
|
||||||
@ -568,7 +565,7 @@ func (a *TestApp) updateChannelTopics(storeChannel *TestChannel) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) updateChannelTopic(storeChannel *TestChannel, storeTopic *TestTopic, topic *Topic) (err error) {
|
func (a *TestApp) updateChannelTopic(storeChannel *testChannel, storeTopic *testTopic, topic *Topic) (err error) {
|
||||||
if storeTopic.topic.Revision != topic.Revision {
|
if storeTopic.topic.Revision != topic.Revision {
|
||||||
if storeTopic.topic.Data.TagRevision != topic.Data.TagRevision {
|
if storeTopic.topic.Data.TagRevision != topic.Data.TagRevision {
|
||||||
if err = a.updateChannelTopicTags(storeChannel, storeTopic); err != nil {
|
if err = a.updateChannelTopicTags(storeChannel, storeTopic); err != nil {
|
||||||
@ -599,7 +596,7 @@ func (a *TestApp) updateChannelTopic(storeChannel *TestChannel, storeTopic *Test
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) updateChannelTopicTags(storeChannel *TestChannel, storeTopic *TestTopic) (err error) {
|
func (a *TestApp) updateChannelTopicTags(storeChannel *testChannel, storeTopic *testTopic) (err error) {
|
||||||
var tags []Tag
|
var tags []Tag
|
||||||
if storeTopic.topic.Revision == 0 {
|
if storeTopic.topic.Revision == 0 {
|
||||||
params := &TestAPIParams{query: "/channels/{channelID}/topics/{topicID}/tags",
|
params := &TestAPIParams{query: "/channels/{channelID}/topics/{topicID}/tags",
|
||||||
@ -644,11 +641,11 @@ func (a *TestApp) updateCards() (err error) {
|
|||||||
delete(a.contacts, card.ID)
|
delete(a.contacts, card.ID)
|
||||||
} else {
|
} else {
|
||||||
// set new card
|
// set new card
|
||||||
contactData := &TestContactData{card: card, articles: make(map[string]*Article), channels: make(map[string]*TestChannel),
|
contactData := &TestContactData{card: card, articles: make(map[string]*Article), channels: make(map[string]*testChannel),
|
||||||
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
||||||
profileRevision: card.Data.ProfileRevision, token: a.token}
|
profileRevision: card.Data.ProfileRevision, token: a.token}
|
||||||
a.contacts[card.ID] = contactData
|
a.contacts[card.ID] = contactData
|
||||||
if err = contactData.UpdateContact(); err != nil {
|
if err = contactData.updateContact(); err != nil {
|
||||||
contactData.offsync = true
|
contactData.offsync = true
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
}
|
}
|
||||||
@ -674,11 +671,11 @@ func (a *TestApp) updateCards() (err error) {
|
|||||||
if err = TestAPIRequest(GetCard, params, response); err != nil {
|
if err = TestAPIRequest(GetCard, params, response); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
contactData := &TestContactData{card: card, articles: make(map[string]*Article), channels: make(map[string]*TestChannel),
|
contactData := &TestContactData{card: card, articles: make(map[string]*Article), channels: make(map[string]*testChannel),
|
||||||
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
||||||
profileRevision: card.Data.ProfileRevision, token: a.token}
|
profileRevision: card.Data.ProfileRevision, token: a.token}
|
||||||
a.contacts[card.ID] = contactData
|
a.contacts[card.ID] = contactData
|
||||||
if err = contactData.UpdateContact(); err != nil {
|
if err = contactData.updateContact(); err != nil {
|
||||||
contactData.offsync = true
|
contactData.offsync = true
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
}
|
}
|
||||||
@ -690,7 +687,7 @@ func (a *TestApp) updateCards() (err error) {
|
|||||||
contactData.card.Data.NotifiedView = card.Data.NotifiedView
|
contactData.card.Data.NotifiedView = card.Data.NotifiedView
|
||||||
contactData.card.Data.DetailRevision = card.Data.DetailRevision
|
contactData.card.Data.DetailRevision = card.Data.DetailRevision
|
||||||
contactData.card.Data.ProfileRevision = card.Data.ProfileRevision
|
contactData.card.Data.ProfileRevision = card.Data.ProfileRevision
|
||||||
if err = contactData.UpdateContact(); err != nil {
|
if err = contactData.updateContact(); err != nil {
|
||||||
contactData.offsync = true
|
contactData.offsync = true
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
}
|
}
|
||||||
@ -755,6 +752,7 @@ func (a *TestApp) updateApp(rev *Revision) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Connect provides a test handler for the websocket connection
|
||||||
func (a *TestApp) Connect(token string) error {
|
func (a *TestApp) Connect(token string) error {
|
||||||
var revision Revision
|
var revision Revision
|
||||||
var data []byte
|
var data []byte
|
||||||
@ -789,7 +787,7 @@ func (a *TestApp) Connect(token string) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) setCondition(test *TestCondition) {
|
func (a *TestApp) setCondition(test *testCondition) {
|
||||||
a.mutex.Lock()
|
a.mutex.Lock()
|
||||||
if test.check(a) {
|
if test.check(a) {
|
||||||
test.channel <- true
|
test.channel <- true
|
||||||
@ -805,10 +803,11 @@ func (a *TestApp) clearCondition() {
|
|||||||
a.mutex.Unlock()
|
a.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//WaitFor provides a helper waiting for a condition to be met
|
||||||
func (a *TestApp) WaitFor(check func(*TestApp) bool) error {
|
func (a *TestApp) WaitFor(check func(*TestApp) bool) error {
|
||||||
var done = make(chan bool, 1)
|
var done = make(chan bool, 1)
|
||||||
var wake = make(chan bool, 1)
|
var wake = make(chan bool, 1)
|
||||||
a.setCondition(&TestCondition{channel: done, check: check})
|
a.setCondition(&testCondition{channel: done, check: check})
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(testTimeout * time.Second)
|
time.Sleep(testTimeout * time.Second)
|
||||||
wake <- true
|
wake <- true
|
||||||
@ -825,6 +824,7 @@ func (a *TestApp) WaitFor(check func(*TestApp) bool) error {
|
|||||||
|
|
||||||
/*** endpoint test function ***/
|
/*** endpoint test function ***/
|
||||||
|
|
||||||
|
//TestAPIParams holds the config for an endpoint test
|
||||||
type TestAPIParams struct {
|
type TestAPIParams struct {
|
||||||
restType string
|
restType string
|
||||||
path map[string]string
|
path map[string]string
|
||||||
@ -836,12 +836,14 @@ type TestAPIParams struct {
|
|||||||
credentials string
|
credentials string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TestAPIResponse holds the endpoint test response
|
||||||
type TestAPIResponse struct {
|
type TestAPIResponse struct {
|
||||||
code int
|
code int
|
||||||
data interface{}
|
data interface{}
|
||||||
header map[string][]string
|
header map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TestAPIRequest tests and endpoint with provided params
|
||||||
func TestAPIRequest(endpoint func(http.ResponseWriter, *http.Request), params *TestAPIParams, resp *TestAPIResponse) (err error) {
|
func TestAPIRequest(endpoint func(http.ResponseWriter, *http.Request), params *TestAPIParams, resp *TestAPIResponse) (err error) {
|
||||||
|
|
||||||
var r *http.Request
|
var r *http.Request
|
||||||
|
@ -36,6 +36,7 @@ type testContact struct {
|
|||||||
D testCard
|
D testCard
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TestGroup provides the setup accounts for a test case
|
||||||
type TestGroup struct {
|
type TestGroup struct {
|
||||||
A testContact
|
A testContact
|
||||||
B testContact
|
B testContact
|
||||||
@ -43,6 +44,7 @@ type TestGroup struct {
|
|||||||
D testContact
|
D testContact
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetTestRevision retrieves the notified revisions
|
||||||
func GetTestRevision(status chan *Revision) (rev *Revision) {
|
func GetTestRevision(status chan *Revision) (rev *Revision) {
|
||||||
time.Sleep(testRevisionWait * time.Millisecond)
|
time.Sleep(testRevisionWait * time.Millisecond)
|
||||||
for {
|
for {
|
||||||
@ -55,6 +57,7 @@ func GetTestRevision(status chan *Revision) (rev *Revision) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//APITestData is a helper function for testing asset download
|
||||||
func APITestData(
|
func APITestData(
|
||||||
endpoint func(http.ResponseWriter, *http.Request),
|
endpoint func(http.ResponseWriter, *http.Request),
|
||||||
requestType string,
|
requestType string,
|
||||||
@ -112,6 +115,7 @@ func APITestData(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//APITestMsg is a helper function for an endpoint test
|
||||||
func APITestMsg(
|
func APITestMsg(
|
||||||
endpoint func(http.ResponseWriter, *http.Request),
|
endpoint func(http.ResponseWriter, *http.Request),
|
||||||
requestType string,
|
requestType string,
|
||||||
@ -173,6 +177,7 @@ func APITestMsg(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//APITestUpload is a helper function for asset upload test
|
||||||
func APITestUpload(
|
func APITestUpload(
|
||||||
endpoint func(http.ResponseWriter, *http.Request),
|
endpoint func(http.ResponseWriter, *http.Request),
|
||||||
requestType string,
|
requestType string,
|
||||||
@ -668,6 +673,7 @@ func addTestAccount(username string) (guid string, token string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NewRequest provides a lower level helper function for an endpoint test
|
||||||
func NewRequest(rest string, path string, obj interface{}) (*http.Request, *httptest.ResponseRecorder, error) {
|
func NewRequest(rest string, path string, obj interface{}) (*http.Request, *httptest.ResponseRecorder, error) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
if obj != nil {
|
if obj != nil {
|
||||||
@ -688,6 +694,8 @@ type statusHandler struct{}
|
|||||||
func (h *statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
Status(w, r)
|
Status(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//StatusConnection provides a test interface for the websocket updates
|
||||||
func StatusConnection(token string, rev *Revision) (ws *websocket.Conn, err error) {
|
func StatusConnection(token string, rev *Revision) (ws *websocket.Conn, err error) {
|
||||||
var data []byte
|
var data []byte
|
||||||
var dataType int
|
var dataType int
|
||||||
|
Loading…
Reference in New Issue
Block a user