github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/cmd/abapEnvironmentAssembleConfirm_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package cmd 5 6 import ( 7 "testing" 8 "time" 9 10 abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" 11 "github.com/SAP/jenkins-library/pkg/abaputils" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestPolling(t *testing.T) { 16 t.Run("Run polling", func(t *testing.T) { 17 var repo abaputils.Repository 18 b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M") 19 var buildsWithRepo []buildWithRepository 20 bWR := buildWithRepository{ 21 build: b, 22 repo: repo, 23 } 24 buildsWithRepo = append(buildsWithRepo, bWR) 25 timeout := time.Duration(600 * time.Second) 26 pollInterval := time.Duration(1 * time.Second) 27 err := polling(buildsWithRepo, timeout, pollInterval) 28 assert.NoError(t, err) 29 assert.Equal(t, abapbuild.Finished, buildsWithRepo[0].build.RunState) 30 }) 31 } 32 func TestStartingConfirm(t *testing.T) { 33 t.Run("Run starting", func(t *testing.T) { 34 client := &abapbuild.ClMock{ 35 Token: "MyToken", 36 } 37 conn := new(abapbuild.Connector) 38 conn.Client = client 39 conn.Header = make(map[string][]string) 40 var repos []abaputils.Repository 41 repo := abaputils.Repository{ 42 Name: "RepoA", 43 Version: "0001", 44 PackageName: "Package", 45 PackageType: "AOI", 46 SpLevel: "0000", 47 PatchLevel: "0000", 48 Status: "P", 49 Namespace: "/DEMO/", 50 } 51 repos = append(repos, repo) 52 repo.Status = "R" 53 repo.InBuildScope = true 54 repos = append(repos, repo) 55 56 builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second)) 57 assert.NoError(t, err) 58 assert.Equal(t, 1, len(builds)) 59 assert.Equal(t, abapbuild.Accepted, builds[0].build.RunState) 60 }) 61 } 62 63 func TestStartingConfirmInvalidInput(t *testing.T) { 64 t.Run("Run starting", func(t *testing.T) { 65 client := &abapbuild.ClMock{ 66 Token: "MyToken", 67 } 68 conn := new(abapbuild.Connector) 69 conn.Client = client 70 conn.Header = make(map[string][]string) 71 var repos []abaputils.Repository 72 repo := abaputils.Repository{ 73 Name: "RepoA", 74 InBuildScope: true, 75 } 76 repos = append(repos, repo) 77 _, err := startingConfirm(repos, *conn, time.Duration(0*time.Second)) 78 assert.Error(t, err) 79 }) 80 } 81 82 func TestStartingConfirmReleaseFailed(t *testing.T) { 83 t.Run("Run starting release failed", func(t *testing.T) { 84 client := &abapbuild.ClMock{ 85 Token: "MyToken", 86 } 87 conn := new(abapbuild.Connector) 88 conn.Client = client 89 conn.Header = make(map[string][]string) 90 var repos []abaputils.Repository 91 repo := abaputils.Repository{ 92 Name: "RepoA", 93 Version: "0001", 94 PackageName: "Package", 95 PackageType: "AOI", 96 SpLevel: "0000", 97 PatchLevel: "0000", 98 Status: "L", 99 Namespace: "/DEMO/", 100 InBuildScope: true, 101 } 102 repos = append(repos, repo) 103 repo.Status = "R" 104 repos = append(repos, repo) 105 106 builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second)) 107 assert.Error(t, err) 108 assert.Equal(t, 1, len(builds)) 109 assert.Equal(t, abapbuild.Accepted, builds[0].build.RunState) 110 }) 111 }