Skip to content

Commit

Permalink
add github tests (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
wj00037 authored Nov 8, 2024
1 parent a963368 commit 10beb8f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 8 additions & 9 deletions auth/gitee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -62,5 +61,5 @@ func (s *SuiteUserInRepo) TestVerifyUser() {
}

func TestGitee(t *testing.T) {
suite.Run(t, new(SuiteUserInRepo))
suite.Run(t, new(SuiteGitee))
}
47 changes: 47 additions & 0 deletions auth/github_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 10beb8f

Please sign in to comment.