Skip to content

Commit

Permalink
Changed network and feed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexurquhart committed Jan 22, 2015
1 parent 0600d35 commit c1f0037
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test.sh
*.out
bower_components
watcher/*
Expand Down
12 changes: 7 additions & 5 deletions lib/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Filter type
// Functions take a tweet and return true if it should continue being processed
type TweetFilter func(t *prototweet.Tweet) bool
type TweetFilter func(t *twitterstream.Tweet) bool

// API keys and extent bounding box coordinates
type TwitterAPIConfig struct {
Expand Down Expand Up @@ -60,10 +60,12 @@ func ListenToTwitter(cfg TwitterAPIConfig, filterFunc TweetFilter, doneChan chan
}

// Filter tweeet and send it off
if pTweet, err := ToProtoTweet(tweet); filterFunc(pTweet) && err == nil {
tweetChan <- pTweet
} else if err != nil {
errorChan <- err
if filterFunc(tweet) {
if pTweet, err := ToProtoTweet(tweet); err != nil {
errorChan <- err
} else {
tweetChan <- pTweet
}
}
}
}
Expand Down
27 changes: 15 additions & 12 deletions lib/feed_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tweetmap

import (
"github.com/cdn-madness/tweetmap/protobuf"
"github.com/darkhelmet/twitterstream"
"github.com/stretchr/testify/assert"
"log"
Expand All @@ -21,25 +20,29 @@ func TestListenToTwitter(t *testing.T) {
NorthWest: twitterstream.Point{90, 180},
}

filter := func(t *prototweet.Tweet) bool {
filter := func(t *twitterstream.Tweet) bool {
return true
}

doneChan := make(chan bool)
defer close(doneChan)
tweetChan, errChan := ListenToTwitter(apiCfg, filter, doneChan)

select {
case <-tweetChan:
log.Println("Received tweet")
case err := <-errChan:
// Determine the error type
if _, ok := err.(*ProtoTweetError); !ok {
t.Log(err)
assert.Fail(t, err.Error())
L:
for {
select {
case <-tweetChan:
log.Println("Received tweet")
break L
case err := <-errChan:
// Determine the error type
if _, ok := err.(*ProtoTweetError); !ok {
t.Log(err)
assert.Fail(t, err.Error())
}
case <-time.After(time.Minute):
assert.Fail(t, "No tweets received in past 60 seconds.")
}
case <-time.After(time.Minute):
assert.Fail(t, "No tweets received in past 60 seconds.")
}

}

0 comments on commit c1f0037

Please sign in to comment.