From a9633681899473fac9c79a7adc6401e7a2e07f4c Mon Sep 17 00:00:00 2001 From: wj00037 <1292876134@qq.com> Date: Fri, 8 Nov 2024 17:11:22 +0800 Subject: [PATCH] add auth tests (#22) * add auth tests * fix --- auth/gitee_test.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 7 ++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 auth/gitee_test.go diff --git a/auth/gitee_test.go b/auth/gitee_test.go new file mode 100644 index 0000000..fb892c9 --- /dev/null +++ b/auth/gitee_test.go @@ -0,0 +1,66 @@ +package auth + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +// SuiteUserInRepo used for testing +type SuiteUserInRepo struct { + suite.Suite + Repo string + Owner string +} + +// SetupSuite used for testing +func (s *SuiteUserInRepo) SetupSuite() { + s.Repo = "software-package-server" + s.Owner = "src-openeuler" +} + +// TearDownSuite used for testing +func (s *SuiteUserInRepo) TearDownSuite() { + +} + +func (s *SuiteUserInRepo) TestGetToken() { + // getToken fail + token, err := getToken("user", "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, + Operation: "download", + } + + err := verifyUser(userInRepo) + assert.NotNil(s.T(), err) +} + +func TestGitee(t *testing.T) { + suite.Run(t, new(SuiteUserInRepo)) +} diff --git a/go.mod b/go.mod index 025d721..dd888e1 100644 --- a/go.mod +++ b/go.mod @@ -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