Skip to content

Commit

Permalink
add auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wj00037 committed Nov 8, 2024
1 parent 8277cc9 commit 66d9b9a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
78 changes: 78 additions & 0 deletions auth/gitee_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package auth

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

// SuiteUserInRepo used for testing
type SuiteUserInRepo struct {
suite.Suite
Repo string
Owner string
Token string
Username string
Password string
Operation string
// userInRepo UserInRepo
}

// SetupSuite used for testing
func (s *SuiteUserInRepo) SetupSuite() {
username := os.Getenv("GITEE_USER")
token := os.Getenv("GITEE_TOKEN")
s.Repo = "software-package-server"
s.Owner = "src-openeuler"
s.Username = username
s.Token = token
}

// TearDownSuite used for testing
func (s *SuiteUserInRepo) TearDownSuite() {

}

func (s *SuiteUserInRepo) TestGetToken() {
// getToken fail
token, err := getToken(s.Username, "wrong_pwd")
assert.Equal(s.T(), "", token)
assert.NotNil(s.T(), err.Error())
}

func (s *SuiteUserInRepo) TestCheckRepoOwner() {
// CheckRepoOwner success
userInRepo := UserInRepo{
Repo: s.Repo,
Owner: s.Owner,
}
err := CheckRepoOwner(userInRepo)
assert.Nil(s.T(), err)

// check no_exist repo
userInRepo = UserInRepo{
Repo: "repo",
Owner: "owner",
}
err = CheckRepoOwner(userInRepo)
assert.NotNil(s.T(), err)
}

func (s *SuiteUserInRepo) TestVerifyUser() {
userInRepo := UserInRepo{
Repo: s.Repo,
Owner: s.Owner,
Token: s.Token,
Username: s.Username,
Operation: "download",
}

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

func TestGitee(t *testing.T) {
suite.Run(t, new(SuiteUserInRepo))
}
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ require (
sigs.k8s.io/yaml v1.4.0
)

require github.com/stretchr/testify v1.9.0 // indirect
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.24.6+incompatible
Expand Down

0 comments on commit 66d9b9a

Please sign in to comment.