-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamertweet_test.go
132 lines (115 loc) · 3.8 KB
/
streamertweet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"encoding/json"
"net/http"
"testing"
"github.com/ChimeraCoder/anaconda"
"github.com/joho/godotenv"
)
func TestReadStreamersFunc(t *testing.T) {
t.Log("\tTesting if our ReadStreamers function works correctly")
_, err := ReadStreamers(streamersFile)
if err != nil {
t.Error("Error was not nil for reading streamers: ", err)
}
}
func TestUsersTweetBool(t *testing.T) {
t.Log("\tTesting if we have our streamers formatted and set up correctly")
streams, err := ReadStreamers(streamersFile)
if err != nil {
t.Error("Error was not nil for reading streamers: ", err)
}
for i, streamer := range streams {
if streamer.Tweeted != true {
t.Error("Streamer not marked as tweeted - we would be tweeting on first run!", streams[i])
}
if streamer.Name == "" {
t.Error("Streamer was missing Name", streams[i])
}
if streamer.Twitter == "" {
t.Error("Streamer was missing Twitter", streams[i])
}
if streamer.User == "" {
t.Error("Streamer was missing User", streams[i])
}
}
}
// Test if our twitter creds work and we can auth with twitter
func TestTwitter(t *testing.T) {
keys, err := godotenv.Read()
if err != nil {
t.Error(err)
}
t.Log("\tTesting if we can our authentication tokens are valid and working with the Twitter.com API")
anaconda.SetConsumerKey(keys["TWITKEY"])
anaconda.SetConsumerSecret(keys["TWITSEC"])
client := anaconda.NewTwitterApi(keys["TOK"], keys["TOKSEC"])
ok, err := client.VerifyCredentials()
if err != nil {
t.Log(ok)
t.Error(err)
}
if ok != true {
t.Log(ok)
t.Error(err)
}
}
func TestTwitch(t *testing.T) {
keys, err := godotenv.Read()
if err != nil {
t.Error(err)
}
t.Log("\tTesting if we can authenticate our Client-ID with Twitch.tv API")
twitchtestjson := new(TwitchRoot)
twitchtest := &http.Client{}
req, err := http.NewRequest("GET", "https://api.twitch.tv/kraken"+"/", nil)
if err != nil {
t.Error(err)
}
req.Header.Add("Accept", twitchmime)
req.Header.Add("Client-ID", keys["TWITCHID"])
r, err := twitchtest.Do(req)
if err != nil {
t.Error(err)
}
defer r.Body.Close()
json.NewDecoder(r.Body).Decode(twitchtestjson)
if twitchtestjson.Identified != true {
t.Error("Twitch could not authenticate us")
}
}
// test our length check functions as we expect
func TestLengthCheck(t *testing.T) {
t.Log("\tTesting if we can check a tweet's length correctly")
longString := "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis p"
shortString := "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor."
exactString := "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et ma"
if FitsTweet(longString) != false {
t.Error("FitsTweet allowed a long string")
}
if FitsTweet(shortString) != true {
t.Error("FitsTweet didn't allow a string that fits")
}
if FitsTweet(exactString) != true {
t.Error("FitsTweet didn't allow a 140 chars string")
}
}
// test we can shorten games as we expect
func TestShortGame(t *testing.T) {
t.Log("\tTesting if we can shorten a game's name correctly")
if ShortGame("Counter-Strike: Global Offensive") != "#CSGO" {
t.Error("ShortGame did not return a shortened string for CSGO")
}
if ShortGame("Hearthstone: Heroes of Warcraft") != "#Hearthstone" {
t.Error("ShortGame did not return a shortened string for Hearthstone")
}
if ShortGame("Overwatch") != "#Overwatch" {
t.Error("ShortGame did not return a hashtag version for Overwatch")
}
if ShortGame("Dark Souls") != "Dark Souls" {
t.Error("ShortGame did not simply return the game name if it's not in our list")
}
if ShortGame("") != "some games" {
t.Error("ShortGame did not return 'some games' for an empty game")
}
}