Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyoshiki41 committed Dec 10, 2016
1 parent 91c7be2 commit 06c8d51
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 19 additions & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestFailedToLogin(t *testing.T) {
func TestLogin_StatusCode400(t *testing.T) {
// delete http.Client.Jar
defer teardownHTTPClient()

Expand Down
4 changes: 2 additions & 2 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
9 changes: 1 addition & 8 deletions timeshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 06c8d51

Please sign in to comment.