1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-22 05:33:10 +02:00
sap-jenkins-library/pkg/abap/aakaas/versionables_test.go
tiloKo 3867f37dcf
abapEnvironment automatically building the next package (#4148)
* api user scatch

* cv, pv +steps

* dust wipe

* escape odata values in filter

* use correct validation url

* headers

* add missing error check

* restrict to non revertable packages

* Correct dotted-version-string calculation + tests
2023-01-12 15:47:11 +01:00

132 lines
5.0 KiB
Go

package aakaas
import (
"testing"
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
"github.com/stretchr/testify/assert"
)
func TestCvResolve(t *testing.T) {
//arrange
conn := new(abapbuild.Connector)
mc := abapbuild.NewMockClient()
conn.Client = &mc
vers := versionable{}
t.Run("Factory Success", func(t *testing.T) {
//act
err := vers.constructVersionable("DummyComp", "1.2.3", *conn, "")
//assert
assert.NoError(t, err)
assert.Equal(t, "DummyComp", vers.Name)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0002", vers.TechSpLevel)
assert.Equal(t, "0003", vers.TechPatchLevel)
assert.Equal(t, "1.2.3", vers.Version)
})
t.Run("Factory No Name", func(t *testing.T) {
err := vers.constructVersionable("", "1.2.3", *conn, "")
assert.Error(t, err)
})
t.Run("Factory Version too long", func(t *testing.T) {
err := vers.constructVersionable("DummyComp", "1.0.0.0", *conn, "")
assert.Error(t, err)
})
t.Run("Factory Version too short", func(t *testing.T) {
err := vers.constructVersionable("DummyComp", "1.0", *conn, "")
assert.Error(t, err)
})
t.Run("ComponentVersion NEXT Release Existing", func(t *testing.T) {
mc.AddData(testDataAakaasCVGetReleaseExisting)
err := vers.constructVersionable("DummyComp", wildCard+".0.0", *conn, cvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "2", vers.TechRelease)
assert.Equal(t, "0000", vers.TechSpLevel)
assert.Equal(t, "0000", vers.TechPatchLevel)
assert.Equal(t, "2.0.0", vers.Version)
})
t.Run("ComponentVersion NEXT Release Non Existing", func(t *testing.T) {
mc.AddData(testDataAakaasCVGetReleaseNonExisting)
err := vers.constructVersionable("DummyComp", wildCard+".0.0", *conn, cvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0000", vers.TechSpLevel)
assert.Equal(t, "0000", vers.TechPatchLevel)
assert.Equal(t, "1.0.0", vers.Version)
})
t.Run("ComponentVersion NEXT SP Level Existing", func(t *testing.T) {
mc.AddData(testDataAakaasCVGetSpLevelExisting)
err := vers.constructVersionable("DummyComp", "1."+wildCard+".0", *conn, cvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0008", vers.TechSpLevel)
assert.Equal(t, "0000", vers.TechPatchLevel)
assert.Equal(t, "1.8.0", vers.Version)
})
t.Run("ComponentVersion NEXT SP Level Non Existing", func(t *testing.T) {
//This one should lead to an error later on as AOI is needed - anyway we can't just produce a differen package then customized...
mc.AddData(testDataAakaasCVGetSpLevelNonExisting)
err := vers.constructVersionable("DummyComp", "1."+wildCard+".0", *conn, cvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0001", vers.TechSpLevel)
assert.Equal(t, "0000", vers.TechPatchLevel)
assert.Equal(t, "1.1.0", vers.Version)
})
t.Run("ComponentVersion NEXT Patch Level Existing", func(t *testing.T) {
mc.AddData(testDataAakaasCVGetPatchLevelExisting)
err := vers.constructVersionable("DummyComp", "1.3."+wildCard, *conn, cvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0003", vers.TechSpLevel)
assert.Equal(t, "0047", vers.TechPatchLevel)
assert.Equal(t, "1.3.47", vers.Version)
})
t.Run("ComponentVersion NEXT Patch Level Non Existing", func(t *testing.T) {
//This one should lead to an error later on as AOI is needed - anyway we can't just produce a differen package then customized...
mc.AddData(testDataAakaasCVGetPatchLevelNonExisting)
err := vers.constructVersionable("DummyComp", "1.3."+wildCard, *conn, cvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0003", vers.TechSpLevel)
assert.Equal(t, "0001", vers.TechPatchLevel)
assert.Equal(t, "1.3.1", vers.Version)
})
t.Run("Product Version NEXT Release Existing", func(t *testing.T) {
mc.AddData(testDataAakaasPVGetReleaseExisting)
err := vers.constructVersionable("DummyProd", wildCard+".0.0", *conn, pvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "2", vers.TechRelease)
assert.Equal(t, "0000", vers.TechSpLevel)
assert.Equal(t, "0000", vers.TechPatchLevel)
assert.Equal(t, "2.0.0", vers.Version)
})
t.Run("Product Version NEXT Release Non Existing", func(t *testing.T) {
mc.AddData(testDataAakaasPVGetReleaseNonExisting)
err := vers.constructVersionable("DummyProd", wildCard+".0.0", *conn, pvQueryURL)
assert.NoError(t, err)
err = vers.resolveNext()
assert.NoError(t, err)
assert.Equal(t, "1", vers.TechRelease)
assert.Equal(t, "0000", vers.TechSpLevel)
assert.Equal(t, "0000", vers.TechPatchLevel)
assert.Equal(t, "1.0.0", vers.Version)
})
}