github.com/jaylevin/jenkins-library@v1.230.4/cmd/abapEnvironmentAssembleConfirm_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
     8  	"github.com/SAP/jenkins-library/pkg/abaputils"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestPolling(t *testing.T) {
    13  	t.Run("Run polling", func(t *testing.T) {
    14  		var repo abaputils.Repository
    15  		b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
    16  		var buildsWithRepo []buildWithRepository
    17  		bWR := buildWithRepository{
    18  			build: b,
    19  			repo:  repo,
    20  		}
    21  		buildsWithRepo = append(buildsWithRepo, bWR)
    22  		timeout := time.Duration(600 * time.Second)
    23  		pollInterval := time.Duration(1 * time.Second)
    24  		err := polling(buildsWithRepo, timeout, pollInterval)
    25  		assert.NoError(t, err)
    26  		assert.Equal(t, abapbuild.Finished, buildsWithRepo[0].build.RunState)
    27  	})
    28  }
    29  func TestStartingConfirm(t *testing.T) {
    30  	t.Run("Run starting", func(t *testing.T) {
    31  		client := &abapbuild.ClMock{
    32  			Token: "MyToken",
    33  		}
    34  		conn := new(abapbuild.Connector)
    35  		conn.Client = client
    36  		conn.Header = make(map[string][]string)
    37  		var repos []abaputils.Repository
    38  		repo := abaputils.Repository{
    39  			Name:        "RepoA",
    40  			Version:     "0001",
    41  			PackageName: "Package",
    42  			PackageType: "AOI",
    43  			SpLevel:     "0000",
    44  			PatchLevel:  "0000",
    45  			Status:      "P",
    46  			Namespace:   "/DEMO/",
    47  		}
    48  		repos = append(repos, repo)
    49  		repo.Status = "R"
    50  		repo.InBuildScope = true
    51  		repos = append(repos, repo)
    52  
    53  		builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
    54  		assert.NoError(t, err)
    55  		assert.Equal(t, 1, len(builds))
    56  		assert.Equal(t, abapbuild.Accepted, builds[0].build.RunState)
    57  	})
    58  }
    59  
    60  func TestStartingConfirmInvalidInput(t *testing.T) {
    61  	t.Run("Run starting", func(t *testing.T) {
    62  		client := &abapbuild.ClMock{
    63  			Token: "MyToken",
    64  		}
    65  		conn := new(abapbuild.Connector)
    66  		conn.Client = client
    67  		conn.Header = make(map[string][]string)
    68  		var repos []abaputils.Repository
    69  		repo := abaputils.Repository{
    70  			Name:         "RepoA",
    71  			InBuildScope: true,
    72  		}
    73  		repos = append(repos, repo)
    74  		_, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
    75  		assert.Error(t, err)
    76  	})
    77  }