2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2021-02-10 12:33:10 +02:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2021-03-11 12:55:12 +02:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
2021-02-10 12:33:10 +02:00
|
|
|
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"
|
2021-10-28 11:01:16 +02:00
|
|
|
repo.InBuildScope = true
|
2021-02-10 12:33:10 +02:00
|
|
|
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{
|
2021-10-28 11:01:16 +02:00
|
|
|
Name: "RepoA",
|
|
|
|
InBuildScope: true,
|
2021-02-10 12:33:10 +02:00
|
|
|
}
|
|
|
|
repos = append(repos, repo)
|
|
|
|
_, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
2022-08-23 15:33:42 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|