diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3f61c18..57ecdcd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -41,6 +41,6 @@ jobs: with: args: -exclude-dir BigFiles -exclude-dir utils ./... - name: Unit tests - run: go test -race -count=1 -v ./... + run: go test -race -count=1 -cover -v ./... - name: cleanup run: rm -f ~/.netrc \ No newline at end of file diff --git a/auth/gitee_test.go b/auth/gitee_test.go index fb892c9..e5f085a 100644 --- a/auth/gitee_test.go +++ b/auth/gitee_test.go @@ -7,32 +7,31 @@ import ( "github.com/stretchr/testify/suite" ) -// SuiteUserInRepo used for testing -type SuiteUserInRepo struct { +// SuiteGitee used for testing +type SuiteGitee struct { suite.Suite Repo string Owner string } // SetupSuite used for testing -func (s *SuiteUserInRepo) SetupSuite() { +func (s *SuiteGitee) SetupSuite() { s.Repo = "software-package-server" s.Owner = "src-openeuler" } // TearDownSuite used for testing -func (s *SuiteUserInRepo) TearDownSuite() { - +func (s *SuiteGitee) TearDownSuite() { } -func (s *SuiteUserInRepo) TestGetToken() { +func (s *SuiteGitee) TestGetToken() { // getToken fail token, err := getToken("user", "wrong_pwd") assert.Equal(s.T(), "", token) assert.NotNil(s.T(), err.Error()) } -func (s *SuiteUserInRepo) TestCheckRepoOwner() { +func (s *SuiteGitee) TestCheckRepoOwner() { // CheckRepoOwner success userInRepo := UserInRepo{ Repo: s.Repo, @@ -50,7 +49,7 @@ func (s *SuiteUserInRepo) TestCheckRepoOwner() { assert.NotNil(s.T(), err) } -func (s *SuiteUserInRepo) TestVerifyUser() { +func (s *SuiteGitee) TestVerifyUser() { userInRepo := UserInRepo{ Repo: s.Repo, Owner: s.Owner, @@ -62,5 +61,5 @@ func (s *SuiteUserInRepo) TestVerifyUser() { } func TestGitee(t *testing.T) { - suite.Run(t, new(SuiteUserInRepo)) + suite.Run(t, new(SuiteGitee)) } diff --git a/auth/github_test.go b/auth/github_test.go new file mode 100644 index 0000000..1c65c84 --- /dev/null +++ b/auth/github_test.go @@ -0,0 +1,47 @@ +package auth + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +// SuiteGithub used for testing +type SuiteGithub struct { + suite.Suite + Username string + Password string +} + +// SetupSuite used for testing +func (s *SuiteGithub) SetupSuite() { + s.Username = "username" + s.Password = "password" +} + +// TearDownSuite used for testing +func (s *SuiteGithub) TearDownSuite() { +} + +func (s *SuiteGithub) TestStatic() { + // Static success + static := Static(s.Username, s.Password) + err := static(s.Username, s.Password) + assert.Nil(s.T(), err) + + // Static fail + static = Static(s.Username, s.Password) + err = static(s.Username, "wrong_pwd") + assert.NotNil(s.T(), err) +} + +func (s *SuiteGithub) TestGithubOrg() { + githubAuth := GithubOrg("github_org") + err := githubAuth("user", "token") + assert.NotNil(s.T(), err) +} + +func TestGithub(t *testing.T) { + suite.Run(t, new(SuiteGithub)) +}