Skip to content

Commit

Permalink
Ensure HTTP failure is handled in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorfly committed Apr 25, 2021
1 parent a0ac0ea commit 7e6875d
Show file tree
Hide file tree
Showing 19 changed files with 833 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,24 @@ func TestClient_StartCommercial(t *testing.T) {
}

}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.StartCommercial(&StartCommercialParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}
40 changes: 40 additions & 0 deletions analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ func TestGetExtensionAnalytics(t *testing.T) {
t.Errorf("expected extension analytics url not to be an empty string, got \"%s\"", resp.Data.ExtensionAnalytics[0].URL)
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.GetExtensionAnalytics(&ExtensionAnalyticsParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestGetGameAnalytics(t *testing.T) {
Expand Down Expand Up @@ -135,4 +155,24 @@ func TestGetGameAnalytics(t *testing.T) {
t.Errorf("expected game analytics url not to be an empty string, got \"%s\"", resp.Data.GameAnalytics[0].URL)
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.GetGameAnalytics(&GameAnalyticsParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}
100 changes: 100 additions & 0 deletions authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ func TestRequestAppAccessToken(t *testing.T) {
t.Errorf("expected ExpiresIn to not be \"0\"")
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.RequestAppAccessToken([]string{"some-scope"})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestRequestUserAccessToken(t *testing.T) {
Expand Down Expand Up @@ -257,6 +277,26 @@ func TestRequestUserAccessToken(t *testing.T) {
t.Errorf("expected number of scope to be \"%d\", got \"%d\"", len(testCase.scopes), len(resp.Data.Scopes))
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.RequestUserAccessToken("valid-auth-code")
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestRefreshUserAccessToken(t *testing.T) {
Expand Down Expand Up @@ -380,6 +420,26 @@ func TestRefreshUserAccessToken(t *testing.T) {
t.Errorf("expected number of scope to be \"%d\", got \"%d\"", len(testCase.expectedScopes), len(resp.Data.Scopes))
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.RefreshUserAccessToken("refresh-token")
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestRevokeUserAccessToken(t *testing.T) {
Expand Down Expand Up @@ -447,6 +507,26 @@ func TestRevokeUserAccessToken(t *testing.T) {
continue
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.RevokeUserAccessToken("access-token")
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestValidateToken(t *testing.T) {
Expand Down Expand Up @@ -529,4 +609,24 @@ func TestValidateToken(t *testing.T) {
t.Errorf("expected user token to be %s, got %s", initialUserToken, c.opts.UserAccessToken)
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, _, err := c.ValidateToken("access-token")
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}
39 changes: 39 additions & 0 deletions bits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,26 @@ func TestClient_GetBitsLeaderboard(t *testing.T) {
if resp.Data.Total < 1 {
t.Error("expected Total to be more than zero")
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.GetBitsLeaderboard(&BitsLeaderboardParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

Expand Down Expand Up @@ -599,4 +618,24 @@ func TestClient_GetCheermotes(t *testing.T) {
t.Errorf("expected tier count of \"%d\", got \"%d\"", testCase.initialTiersCount, len(cheermotes.Tiers))
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.GetCheermotes(&CheermotesParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}
20 changes: 20 additions & 0 deletions channels_editors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ func TestGetChannelEditors(t *testing.T) {
t.Errorf("expected status code to be \"%d\", got \"%d\"", testCase.statusCode, resp.StatusCode)
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.GetChannelEditors(&ChannelEditorsParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}
60 changes: 60 additions & 0 deletions channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ func TestSearchChannels(t *testing.T) {
}
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.SearchChannels(&SearchChannelsParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestGetChannelInformation(t *testing.T) {
Expand Down Expand Up @@ -196,6 +216,26 @@ func TestGetChannelInformation(t *testing.T) {
}
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.GetChannelInformation(&GetChannelInformationParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}

func TestEditChannelInformation(t *testing.T) {
Expand Down Expand Up @@ -269,4 +309,24 @@ func TestEditChannelInformation(t *testing.T) {
t.Errorf("expected status code to be \"%d\", got \"%d\"", testCase.statusCode, resp.StatusCode)
}
}

// Test with HTTP Failure
options := &Options{
ClientID: "my-client-id",
HTTPClient: &badMockHTTPClient{
newMockHandler(0, "", nil),
},
}
c := &Client{
opts: options,
}

_, err := c.EditChannelInformation(&EditChannelInformationParams{})
if err == nil {
t.Error("expected error but got nil")
}

if err.Error() != "Failed to execute API request: Oops, that's bad :(" {
t.Error("expected error does match return error")
}
}
Loading

0 comments on commit 7e6875d

Please sign in to comment.