forked from metalogical/BigFiles
-
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.
增加单元测试
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"io" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func Test_getParsedResponse(t *testing.T) { | ||
type args struct { | ||
method string | ||
path string | ||
header http.Header | ||
body io.Reader | ||
obj interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "Test GET request with correct repo and owner", | ||
args: args{ | ||
method: "GET", | ||
path: "https://gitee.com/api/v5/repos/src-openeuler/software-package-server", | ||
header: http.Header{contentType: []string{"application/json;charset=UTF-8"}}, | ||
body: nil, | ||
obj: nil, | ||
}, | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "Test GET request with wrong repo and owner", | ||
args: args{ | ||
method: "GET", | ||
path: "https://gitee.com/api/v5/repos/owner/repo", | ||
header: http.Header{contentType: []string{"application/json;charset=UTF-8"}}, | ||
body: nil, | ||
obj: nil, | ||
}, | ||
wantErr: assert.Error, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.wantErr(t, getParsedResponse(tt.args.method, tt.args.path, tt.args.header, tt.args.body, tt.args.obj), fmt.Sprintf("getParsedResponse(%v, %v, %v, %v, %v)", tt.args.method, tt.args.path, tt.args.header, tt.args.body, tt.args.obj)) | ||
}) | ||
} | ||
} |