Skip to content

Commit

Permalink
add: add test
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
Zherphy committed Nov 30, 2024
1 parent 227bafb commit 3801d89
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions auth/gitee_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth

import (
"github.com/metalogical/BigFiles/config"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -10,19 +11,49 @@ import (
// SuiteGitee used for testing
type SuiteGitee struct {
suite.Suite
Repo string
Owner string
cfg config.Config
Repo string
Owner string
UserName string
Password string
}

// SetupSuite used for testing
func (s *SuiteGitee) SetupSuite() {
s.Repo = "software-package-server"
s.Owner = "src-openeuler"
s.UserName = "user"
s.Password = "wrong_pwd"
s.cfg = config.Config{
ClientId: "clientId",
ClientSecret: "clientSecret",
DefaultToken: "defaultToken",
}
}

func (s *SuiteGitee) TestInit() {
//Init success
err := Init(&s.cfg)
assert.Nil(s.T(), err)
}

func (s *SuiteGitee) TestGiteeAuth() {
// GiteeAuth fail
userInRepo := UserInRepo{
Repo: s.Repo,
Owner: s.Owner,
Username: s.UserName,
Password: s.Password,
Operation: "download",
}
giteeAuth := GiteeAuth()
err := giteeAuth(userInRepo)
assert.NotNil(s.T(), err)
}

func (s *SuiteGitee) TestGetToken() {
// getToken fail
token, err := getToken("user", "wrong_pwd")
token, err := getToken(s.UserName, s.Password)
assert.Equal(s.T(), "", token)
assert.NotNil(s.T(), err.Error())
}
Expand Down Expand Up @@ -54,6 +85,10 @@ func (s *SuiteGitee) TestVerifyUser() {

err := verifyUser(userInRepo)
assert.NotNil(s.T(), err)

userInRepo.Operation = "upload"
err = verifyUser(userInRepo)
assert.NotNil(s.T(), err)
}

func TestGitee(t *testing.T) {
Expand Down

0 comments on commit 3801d89

Please sign in to comment.