Skip to content

Commit

Permalink
add: add test
Browse files Browse the repository at this point in the history
增加单元测试
  • Loading branch information
Zherphy committed Dec 4, 2024
1 parent 762c19c commit 7b51130
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions auth/client_test.go
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))
})
}
}

0 comments on commit 7b51130

Please sign in to comment.