1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/abapEnvironmentAssembleConfirm_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* 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>
2023-05-03 21:02:11 +05:00

112 lines
2.9 KiB
Go

//go:build unit
// +build unit
package cmd
import (
"testing"
"time"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/SAP/jenkins-library/pkg/abaputils"
"github.com/stretchr/testify/assert"
)
func TestPolling(t *testing.T) {
t.Run("Run polling", func(t *testing.T) {
var repo abaputils.Repository
b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
var buildsWithRepo []buildWithRepository
bWR := buildWithRepository{
build: b,
repo: repo,
}
buildsWithRepo = append(buildsWithRepo, bWR)
timeout := time.Duration(600 * time.Second)
pollInterval := time.Duration(1 * time.Second)
err := polling(buildsWithRepo, timeout, pollInterval)
assert.NoError(t, err)
assert.Equal(t, abapbuild.Finished, buildsWithRepo[0].build.RunState)
})
}
func TestStartingConfirm(t *testing.T) {
t.Run("Run starting", func(t *testing.T) {
client := &abapbuild.ClMock{
Token: "MyToken",
}
conn := new(abapbuild.Connector)
conn.Client = client
conn.Header = make(map[string][]string)
var repos []abaputils.Repository
repo := abaputils.Repository{
Name: "RepoA",
Version: "0001",
PackageName: "Package",
PackageType: "AOI",
SpLevel: "0000",
PatchLevel: "0000",
Status: "P",
Namespace: "/DEMO/",
}
repos = append(repos, repo)
repo.Status = "R"
repo.InBuildScope = true
repos = append(repos, repo)
builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
assert.NoError(t, err)
assert.Equal(t, 1, len(builds))
assert.Equal(t, abapbuild.Accepted, builds[0].build.RunState)
})
}
func TestStartingConfirmInvalidInput(t *testing.T) {
t.Run("Run starting", func(t *testing.T) {
client := &abapbuild.ClMock{
Token: "MyToken",
}
conn := new(abapbuild.Connector)
conn.Client = client
conn.Header = make(map[string][]string)
var repos []abaputils.Repository
repo := abaputils.Repository{
Name: "RepoA",
InBuildScope: true,
}
repos = append(repos, repo)
_, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
assert.Error(t, err)
})
}
func TestStartingConfirmReleaseFailed(t *testing.T) {
t.Run("Run starting release failed", func(t *testing.T) {
client := &abapbuild.ClMock{
Token: "MyToken",
}
conn := new(abapbuild.Connector)
conn.Client = client
conn.Header = make(map[string][]string)
var repos []abaputils.Repository
repo := abaputils.Repository{
Name: "RepoA",
Version: "0001",
PackageName: "Package",
PackageType: "AOI",
SpLevel: "0000",
PatchLevel: "0000",
Status: "L",
Namespace: "/DEMO/",
InBuildScope: true,
}
repos = append(repos, repo)
repo.Status = "R"
repos = append(repos, repo)
builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
assert.Error(t, err)
assert.Equal(t, 1, len(builds))
assert.Equal(t, abapbuild.Accepted, builds[0].build.RunState)
})
}