mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
|
|
"github.com/google/go-github/v45/github"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type ghSetCommitRepoService struct {
|
|
serviceError error
|
|
owner string
|
|
ref string
|
|
repo string
|
|
status *github.RepoStatus
|
|
}
|
|
|
|
func (g *ghSetCommitRepoService) CreateStatus(ctx context.Context, owner, repo, ref string, status *github.RepoStatus) (*github.RepoStatus, *github.Response, error) {
|
|
g.owner = owner
|
|
g.repo = repo
|
|
g.ref = ref
|
|
g.status = status
|
|
|
|
return nil, nil, g.serviceError
|
|
}
|
|
|
|
func TestRunGithubSetCommitStatus(t *testing.T) {
|
|
ctx := context.Background()
|
|
telemetryData := telemetry.CustomData{}
|
|
|
|
t.Run("success case", func(t *testing.T) {
|
|
config := githubSetCommitStatusOptions{CommitID: "testSha", Context: "test /context", Description: "testDescription", Owner: "testOrg", Repository: "testRepo", Status: "success", TargetURL: "https://test.url"}
|
|
ghRepo := ghSetCommitRepoService{}
|
|
err := runGithubSetCommitStatus(ctx, &config, &telemetryData, &ghRepo)
|
|
expectedStatus := github.RepoStatus{Context: &config.Context, Description: &config.Description, State: &config.Status, TargetURL: &config.TargetURL}
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, config.CommitID, ghRepo.ref)
|
|
assert.Equal(t, config.Owner, ghRepo.owner)
|
|
assert.Equal(t, config.Repository, ghRepo.repo)
|
|
assert.Equal(t, &expectedStatus, ghRepo.status)
|
|
})
|
|
|
|
t.Run("error calling GitHub", func(t *testing.T) {
|
|
config := githubSetCommitStatusOptions{CommitID: "testSha", Owner: "testOrg", Repository: "testRepo", Status: "pending"}
|
|
ghRepo := ghSetCommitRepoService{serviceError: fmt.Errorf("gh test error")}
|
|
err := runGithubSetCommitStatus(ctx, &config, &telemetryData, &ghRepo)
|
|
assert.EqualError(t, err, "failed to set status 'pending' on commitId 'testSha': gh test error")
|
|
})
|
|
}
|