From 06c8d511e528d1fb8d79dc5996163691b096e0c6 Mon Sep 17 00:00:00 2001 From: yyoshiki41 Date: Sun, 11 Dec 2016 03:17:16 +0900 Subject: [PATCH] fixed tests --- auth.go | 4 ++-- auth_test.go | 20 +++++++++++++++++++- client_test.go | 16 ++++++++-------- login_test.go | 2 +- stream_test.go | 4 ++-- timeshift_test.go | 9 +-------- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/auth.go b/auth.go index 16d0954..9755f76 100644 --- a/auth.go +++ b/auth.go @@ -14,13 +14,13 @@ import ( // AuthorizeToken returns an enables auth_token and error, // and sets auth_token in Client. // Is is a alias function that wraps Auth1Fms and Auth2Fms. -func (c *Client) AuthorizeToken(ctx context.Context, pngFilePath string) (string, error) { +func (c *Client) AuthorizeToken(ctx context.Context, pngFile string) (string, error) { authToken, length, offset, err := c.Auth1Fms(ctx) if err != nil { return "", err } - f, err := os.Open(pngFilePath) + f, err := os.Open(pngFile) if err != nil { return "", err } diff --git a/auth_test.go b/auth_test.go index 5a07d7f..af8240b 100644 --- a/auth_test.go +++ b/auth_test.go @@ -9,6 +9,10 @@ import ( ) func TestAuthorizeToken(t *testing.T) { + if isOutsideJP() { + t.Skip("Skipping test in limited mode.") + } + c, err := New("") if err != nil { t.Fatalf("Failed to construct client: %s", err) @@ -25,6 +29,20 @@ func TestAuthorizeToken(t *testing.T) { } } +func TestAuthorizeToken_NotExistAuthkeyFile(t *testing.T) { + c, err := New("") + if err != nil { + t.Fatalf("Failed to construct client: %s", err) + } + + ctx := context.Background() + pngFile := path.Join(testdataDir, "not_exist_authkey.png") + _, err = c.AuthorizeToken(ctx, pngFile) + if err == nil { + t.Error(err) + } +} + func TestAuth1Fms(t *testing.T) { c, err := New("") if err != nil { @@ -95,7 +113,7 @@ func TestVerifyAuth2FmsResponse(t *testing.T) { err := verifyAuth2FmsResponse(c.slc) if c.expectedErr { if err == nil { - t.Error("expected error has occurred.") + t.Error("Should detect an error.") } continue } diff --git a/client_test.go b/client_test.go index d4713fc..6ba1b8c 100644 --- a/client_test.go +++ b/client_test.go @@ -16,7 +16,7 @@ func TestNew(t *testing.T) { } } -func TestEmptyHTTPClient(t *testing.T) { +func TestNew_EmptyHTTPClient(t *testing.T) { var c *http.Client SetHTTPClient(c) @@ -42,7 +42,7 @@ func TestNewRequest(t *testing.T) { } } -func TestNewRequestWithAuthToken(t *testing.T) { +func TestNewRequest_WithAuthToken(t *testing.T) { const expected = "auth_token" client, err := New(expected) @@ -61,7 +61,7 @@ func TestNewRequestWithAuthToken(t *testing.T) { } } -func TestNewRequestWithContext(t *testing.T) { +func TestNewRequest_WithContext(t *testing.T) { client, err := New("") if err != nil { t.Fatalf("Failed to construct client: %s", err) @@ -87,7 +87,7 @@ func TestNewRequestWithContext(t *testing.T) { } } -func TestNewRequestWithEmptyContext(t *testing.T) { +func TestNewRequest_WithEmptyContext(t *testing.T) { client, err := New("") if err != nil { t.Fatalf("Failed to construct client: %s", err) @@ -100,7 +100,7 @@ func TestNewRequestWithEmptyContext(t *testing.T) { } } -func TestClientAreaID(t *testing.T) { +func TestClient_AreaID(t *testing.T) { client, err := New("") if err != nil { t.Errorf("Failed to construct client: %s", err) @@ -115,7 +115,7 @@ func TestClientAreaID(t *testing.T) { } } -func TestClientSetAreaID(t *testing.T) { +func TestClient_SetAreaID(t *testing.T) { client, err := New("") if err != nil { t.Errorf("Failed to construct client: %s", err) @@ -129,7 +129,7 @@ func TestClientSetAreaID(t *testing.T) { } } -func TestSetJar(t *testing.T) { +func TestClient_SetJar(t *testing.T) { client, err := New("") if err != nil { t.Errorf("Failed to construct client: %s", err) @@ -147,7 +147,7 @@ func TestSetJar(t *testing.T) { } } -func TestSetAuthTokenHeader(t *testing.T) { +func TestClient_SetAuthTokenHeader(t *testing.T) { client, err := New("") if err != nil { t.Errorf("Failed to construct client: %s", err) diff --git a/login_test.go b/login_test.go index a4d9485..78e1c83 100644 --- a/login_test.go +++ b/login_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func TestFailedToLogin(t *testing.T) { +func TestLogin_StatusCode400(t *testing.T) { // delete http.Client.Jar defer teardownHTTPClient() diff --git a/stream_test.go b/stream_test.go index deb0718..a6a50a7 100644 --- a/stream_test.go +++ b/stream_test.go @@ -16,8 +16,8 @@ func TestGetStreamMultiURL(t *testing.T) { } } -func TestNotExistsStreamMultiURL(t *testing.T) { - _, err := GetStreamMultiURL("TEST_LFR") +func TestGetStreamMultiURL_EmptyStationID(t *testing.T) { + _, err := GetStreamMultiURL("") if err == nil { t.Error("Should detect an error.") } diff --git a/timeshift_test.go b/timeshift_test.go index 32e0bdc..df53f7b 100644 --- a/timeshift_test.go +++ b/timeshift_test.go @@ -10,16 +10,9 @@ func TestTimeshiftPlaylistM3U8(t *testing.T) { if isOutsideJP() { t.Skip("Skipping test in limited mode.") } - - client, err := New("") - if err != nil { - t.Fatalf("Failed to construct client: %s", err) - } - - _ = client } -func TestEmptyStationIDTimeshiftPlaylistM3U8(t *testing.T) { +func TestTimeshiftPlaylistM3U8_EmptyStationID(t *testing.T) { client, err := New("") if err != nil { t.Fatalf("Failed to construct client: %s", err)