-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests which actually poll the BTTV api and ensure certain emotes exist. Emotes we check are: NaM in global emote set WAYTOODANK in pajlada's channel emote set
- Loading branch information
Showing
9 changed files
with
159 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gobttv | ||
|
||
import "testing" | ||
|
||
func TestFindChannelEmoteWAYTOODANK(t *testing.T) { | ||
e := Emote{ | ||
ID: "5ad22a7096065b6c6bddf7f3", | ||
Code: "WAYTOODANK", | ||
ImageType: "gif", | ||
|
||
URLs: URLs{ | ||
X1: "https://cdn.betterttv.net/emote/5ad22a7096065b6c6bddf7f3/1x", | ||
X2: "https://cdn.betterttv.net/emote/5ad22a7096065b6c6bddf7f3/2x", | ||
X4: "https://cdn.betterttv.net/emote/5ad22a7096065b6c6bddf7f3/3x", | ||
}, | ||
} | ||
|
||
found := false | ||
|
||
c := make(chan struct{}) | ||
onResponse := func(response ChannelResponse) { | ||
for _, emote := range response.ChannelEmotes { | ||
if emote == e { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
close(c) | ||
} | ||
|
||
api.GetChannel("11148817", onResponse, onHTTPError(t), onInternalError(t)) | ||
|
||
<-c | ||
if !found { | ||
t.Fatalf("Did not find WAYTOODANK in set of channel emotes, this might be due to the API being changed") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package gobttv | ||
|
||
import "testing" | ||
|
||
func onHTTPError(t *testing.T) func(statusCode int, statusMessage, errorMessage string) { | ||
return func(statusCode int, statusMessage, errorMessage string) { | ||
t.Fatalf("HTTP error %d (%s): %s", statusCode, statusMessage, errorMessage) | ||
} | ||
} | ||
|
||
func onInternalError(t *testing.T) func(err error) { | ||
return func(err error) { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package gobttv | ||
|
||
const emoteURLPrefix = "https://cdn.betterttv.net/emote/" | ||
|
||
// Emote is the lowest common description of the BetterTTV emote | ||
type Emote struct { | ||
// Fetched straight from the API | ||
ID string `json:"id"` | ||
Code string `json:"code"` | ||
ImageType string `json:"imageType"` | ||
|
||
// Filled in by us with populateURLs | ||
URLs URLs | ||
} | ||
|
||
func (e *Emote) populateURLs() { | ||
var emoteURL = emoteURLPrefix + e.ID | ||
e.URLs.X1 = emoteURL + "/1x" | ||
e.URLs.X2 = emoteURL + "/2x" | ||
e.URLs.X4 = emoteURL + "/3x" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
package gobttv | ||
|
||
import "github.com/dankeroni/jsonapi" | ||
|
||
// GlobalEmoteData json to struct | ||
type GlobalEmoteData struct { | ||
URL string `json:"url"` | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
ImageType string `json:"imageType"` | ||
Regex string `json:"regex"` | ||
Channel interface{} `json:"channel"` | ||
EmoticonSet string `json:"emoticon_set,omitempty"` | ||
} | ||
import ( | ||
"github.com/dankeroni/jsonapi" | ||
) | ||
|
||
// EmotesResponse json to struct | ||
type EmotesResponse struct { | ||
Status int `json:"status"` | ||
Emotes []GlobalEmoteData `json:"emotes"` | ||
} | ||
type EmotesResponse []Emote | ||
|
||
// GetEmotes request for GET https://api.betterttv.net/emotes | ||
// GetEmotes request for GET https://api.betterttv.net/3/cached/emotes/global | ||
func (bttvAPI *BTTVAPI) GetEmotes(onSuccess func(EmotesResponse), | ||
onHTTPError jsonapi.HTTPErrorCallback, onInternalError jsonapi.InternalErrorCallback) { | ||
var emotes EmotesResponse | ||
onSuccessfulRequest := func() { | ||
for i := range emotes { | ||
emotes[i].populateURLs() | ||
} | ||
|
||
onSuccess(emotes) | ||
} | ||
bttvAPI.Get("/emotes", nil, &emotes, onSuccessfulRequest, | ||
|
||
bttvAPI.Get("/cached/emotes/global", nil, &emotes, onSuccessfulRequest, | ||
onHTTPError, onInternalError) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package gobttv | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var api = New() | ||
|
||
func TestEnsureNaMExists(t *testing.T) { | ||
NaM := Emote{ | ||
ID: "566ca06065dbbdab32ec054e", | ||
Code: "NaM", | ||
ImageType: "png", | ||
|
||
URLs: URLs{ | ||
X1: "https://cdn.betterttv.net/emote/566ca06065dbbdab32ec054e/1x", | ||
X2: "https://cdn.betterttv.net/emote/566ca06065dbbdab32ec054e/2x", | ||
X4: "https://cdn.betterttv.net/emote/566ca06065dbbdab32ec054e/3x", | ||
}, | ||
} | ||
|
||
foundNaM := false | ||
|
||
c := make(chan struct{}) | ||
onResponse := func(emotes EmotesResponse) { | ||
for _, emote := range emotes { | ||
if emote == NaM { | ||
foundNaM = true | ||
break | ||
} | ||
} | ||
|
||
close(c) | ||
} | ||
|
||
api.GetEmotes(onResponse, onHTTPError(t), onInternalError(t)) | ||
|
||
<-c | ||
if !foundNaM { | ||
t.Fatalf("Did not find NaM in set of global emotes, this might be due to the API being changed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package gobttv | ||
|
||
// URLs describes a list of possible URLs for various sizes of an emote | ||
type URLs struct { | ||
X1 string | ||
X2 string | ||
X4 string | ||
} |