From 9e9b402b49393d63ef42b5ea927be9c28054029a Mon Sep 17 00:00:00 2001 From: tiloKo <70266685+tiloKo@users.noreply.github.com> Date: Thu, 16 Feb 2023 12:47:02 +0100 Subject: [PATCH] Variable dotted version string fix #2 (#4233) --- pkg/abap/aakaas/componentVersion.go | 2 +- pkg/abap/aakaas/productVersion.go | 2 +- pkg/abap/aakaas/testData.go | 19 +++++++++++-------- pkg/abap/aakaas/versionables.go | 25 +++++++++++++------------ pkg/abap/aakaas/versionables_test.go | 16 ++++++++-------- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/pkg/abap/aakaas/componentVersion.go b/pkg/abap/aakaas/componentVersion.go index a8696ecd43..efdb24e91c 100644 --- a/pkg/abap/aakaas/componentVersion.go +++ b/pkg/abap/aakaas/componentVersion.go @@ -21,7 +21,7 @@ func (c *ComponentVersion) ConstructComponentVersion(repo abaputils.Repository, if err := c.constructVersionable(repo.Name, repo.VersionYAML, conn, cvQueryURL); err != nil { return err } - if err := c.resolveNext(); err != nil { + if err := c.resolveNext(statusFilterCV); err != nil { return err } diff --git a/pkg/abap/aakaas/productVersion.go b/pkg/abap/aakaas/productVersion.go index ce327a47b5..25743c05de 100644 --- a/pkg/abap/aakaas/productVersion.go +++ b/pkg/abap/aakaas/productVersion.go @@ -21,7 +21,7 @@ func (p *ProductVersion) ConstructProductversion(desc abaputils.AddonDescriptor, if err := p.constructVersionable(desc.AddonProduct, desc.AddonVersionYAML, conn, pvQueryURL); err != nil { return err } - if err := p.resolveNext(); err != nil { + if err := p.resolveNext(statusFilterPV); err != nil { return err } return nil diff --git a/pkg/abap/aakaas/testData.go b/pkg/abap/aakaas/testData.go index 864470e6ea..3a0b10dbe4 100644 --- a/pkg/abap/aakaas/testData.go +++ b/pkg/abap/aakaas/testData.go @@ -9,6 +9,9 @@ package aakaas import abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" +const statusFilterCVEscaped string = "DeliveryStatus+eq+%27R%27" +const statusFilterPVEscaped string = "DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27" + var ResponseCheckPV = `{ "d": { "Name": "/DRNMSPC/PRD01", @@ -39,7 +42,7 @@ var emptyResultBody = `{ var testDataAakaasCVGetReleaseExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+` + statusFilterCVEscaped + `+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: `{ "d": { "results": [ @@ -58,14 +61,14 @@ var testDataAakaasCVGetReleaseExisting = abapbuild.MockData{ var testDataAakaasCVGetReleaseNonExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+` + statusFilterCVEscaped + `+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: emptyResultBody, StatusCode: 200, } var testDataAakaasCVGetSpLevelExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechPatchLevel+eq+%270000%27++and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechSpLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechPatchLevel+eq+%270000%27++and+%28+` + statusFilterCVEscaped + `+%29&%24format=json&%24orderby=TechSpLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: `{ "d": { "results": [ @@ -84,14 +87,14 @@ var testDataAakaasCVGetSpLevelExisting = abapbuild.MockData{ var testDataAakaasCVGetSpLevelNonExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechPatchLevel+eq+%270000%27++and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechSpLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechPatchLevel+eq+%270000%27++and+%28+` + statusFilterCVEscaped + `+%29&%24format=json&%24orderby=TechSpLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: emptyResultBody, StatusCode: 200, } var testDataAakaasCVGetPatchLevelExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechSpLevel+eq+%270003%27+and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechPatchLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechSpLevel+eq+%270003%27+and+%28+` + statusFilterCVEscaped + `+%29&%24format=json&%24orderby=TechPatchLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: `{ "d": { "results": [ @@ -110,14 +113,14 @@ var testDataAakaasCVGetPatchLevelExisting = abapbuild.MockData{ var testDataAakaasCVGetPatchLevelNonExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechSpLevel+eq+%270003%27+and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechPatchLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Component_Version?%24filter=Name+eq+%27DummyComp%27+and+TechRelease+eq+%271%27+and+TechSpLevel+eq+%270003%27+and+%28+` + statusFilterCVEscaped + `+%29&%24format=json&%24orderby=TechPatchLevel+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: emptyResultBody, StatusCode: 200, } var testDataAakaasPVGetReleaseExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Product_Version?%24filter=Name+eq+%27DummyProd%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Product_Version?%24filter=Name+eq+%27DummyProd%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+` + statusFilterPVEscaped + `+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: `{ "d": { "results": [ @@ -136,7 +139,7 @@ var testDataAakaasPVGetReleaseExisting = abapbuild.MockData{ var testDataAakaasPVGetReleaseNonExisting = abapbuild.MockData{ Method: `GET`, - Url: `/odata/aas_ocs_package/xSSDAxC_Product_Version?%24filter=Name+eq+%27DummyProd%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+DeliveryStatus+eq+%27R%27+or+DeliveryStatus+eq+%27C%27+or+DeliveryStatus+eq+%27T%27+or+DeliveryStatus+eq+%27P%27+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel&%24top=1`, + Url: `/odata/aas_ocs_package/xSSDAxC_Product_Version?%24filter=Name+eq+%27DummyProd%27+and+TechSpLevel+eq+%270000%27+and+TechPatchLevel+eq+%270000%27+and+%28+` + statusFilterPVEscaped + `+%29&%24format=json&%24orderby=TechRelease+desc&%24select=Name%2CVersion%2CTechRelease%2CTechSpLevel%2CTechPatchLevel%2CNamespace&%24top=1`, Body: emptyResultBody, StatusCode: 200, } diff --git a/pkg/abap/aakaas/versionables.go b/pkg/abap/aakaas/versionables.go index 9b816efeff..d28ab46cc8 100644 --- a/pkg/abap/aakaas/versionables.go +++ b/pkg/abap/aakaas/versionables.go @@ -13,6 +13,8 @@ import ( ) const wildCard string = "NEXT" +const statusFilterCV string = "DeliveryStatus eq 'R'" +const statusFilterPV string = "DeliveryStatus eq 'T' or DeliveryStatus eq 'P'" type versionable struct { Name string @@ -49,7 +51,7 @@ func (v *versionable) constructVersionable(name string, dottedVersionString stri return nil } -func (v *versionable) resolveNext() error { +func (v *versionable) resolveNext(statusFilter string) error { switch strings.Count(v.Version, wildCard) { case 0: @@ -59,11 +61,11 @@ func (v *versionable) resolveNext() error { var err error switch wildCard { case v.TechRelease: - err = v.resolveRelease() + err = v.resolveRelease(statusFilter) case v.TechSpLevel: - err = v.resolveSpLevel() + err = v.resolveSpLevel(statusFilter) case v.TechPatchLevel: - err = v.resolvePatchLevel() + err = v.resolvePatchLevel(statusFilter) } if err != nil { return err @@ -78,9 +80,8 @@ func (v *versionable) resolveNext() error { return nil } -func (v *versionable) resolveRelease() error { - //take only unrevertable status R/C for packages and T/P for TargetVectors - filter := "Name eq '" + v.Name + "' and TechSpLevel eq '0000' and TechPatchLevel eq '0000' and ( DeliveryStatus eq 'R' or DeliveryStatus eq 'C' or DeliveryStatus eq 'T' or DeliveryStatus eq 'P' )" +func (v *versionable) resolveRelease(statusFilter string) error { + filter := "Name eq '" + v.Name + "' and TechSpLevel eq '0000' and TechPatchLevel eq '0000' and ( " + statusFilter + " )" orderBy := "TechRelease desc" if queryResuult, err := v.queryVersion(filter, orderBy); err != nil { @@ -95,8 +96,8 @@ func (v *versionable) resolveRelease() error { } } -func (v *versionable) resolveSpLevel() error { - filter := "Name eq '" + v.Name + "' and TechRelease eq '" + v.TechRelease + "' and TechPatchLevel eq '0000' and ( DeliveryStatus eq 'R' or DeliveryStatus eq 'C' or DeliveryStatus eq 'T' or DeliveryStatus eq 'P' )" +func (v *versionable) resolveSpLevel(statusFilter string) error { + filter := "Name eq '" + v.Name + "' and TechRelease eq '" + v.TechRelease + "' and TechPatchLevel eq '0000' and ( " + statusFilter + " )" orderBy := "TechSpLevel desc" if queryResuult, err := v.queryVersion(filter, orderBy); err != nil { @@ -111,8 +112,8 @@ func (v *versionable) resolveSpLevel() error { } } -func (v *versionable) resolvePatchLevel() error { - filter := "Name eq '" + v.Name + "' and TechRelease eq '" + v.TechRelease + "' and TechSpLevel eq '" + v.TechSpLevel + "' and ( DeliveryStatus eq 'R' or DeliveryStatus eq 'C' or DeliveryStatus eq 'T' or DeliveryStatus eq 'P' )" +func (v *versionable) resolvePatchLevel(statusFilter string) error { + filter := "Name eq '" + v.Name + "' and TechRelease eq '" + v.TechRelease + "' and TechSpLevel eq '" + v.TechSpLevel + "' and ( " + statusFilter + " )" orderBy := "TechPatchLevel desc" if queryResuult, err := v.queryVersion(filter, orderBy); err != nil { @@ -133,7 +134,7 @@ func (v *versionable) queryVersion(filter string, orderBy string) (*versionable, values := url.Values{} values.Set("$filter", filter) values.Set("$orderby", orderBy) - values.Set("$select", "Name,Version,TechRelease,TechSpLevel,TechPatchLevel") + values.Set("$select", "Name,Version,TechRelease,TechSpLevel,TechPatchLevel,Namespace") //Namespace needed otherwise empty result - will be fixed by OCS shortly values.Set("$format", "json") values.Set("$top", "1") diff --git a/pkg/abap/aakaas/versionables_test.go b/pkg/abap/aakaas/versionables_test.go index 4b9023d302..b9db0218e9 100644 --- a/pkg/abap/aakaas/versionables_test.go +++ b/pkg/abap/aakaas/versionables_test.go @@ -42,7 +42,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasCVGetReleaseExisting) err := vers.constructVersionable("DummyComp", wildCard+".0.0", *conn, cvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterCV) assert.NoError(t, err) assert.Equal(t, "2", vers.TechRelease) assert.Equal(t, "0000", vers.TechSpLevel) @@ -53,7 +53,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasCVGetReleaseNonExisting) err := vers.constructVersionable("DummyComp", wildCard+".0.0", *conn, cvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterCV) assert.NoError(t, err) assert.Equal(t, "1", vers.TechRelease) assert.Equal(t, "0000", vers.TechSpLevel) @@ -64,7 +64,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasCVGetSpLevelExisting) err := vers.constructVersionable("DummyComp", "1."+wildCard+".0", *conn, cvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterCV) assert.NoError(t, err) assert.Equal(t, "1", vers.TechRelease) assert.Equal(t, "0008", vers.TechSpLevel) @@ -76,7 +76,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasCVGetSpLevelNonExisting) err := vers.constructVersionable("DummyComp", "1."+wildCard+".0", *conn, cvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterCV) assert.NoError(t, err) assert.Equal(t, "1", vers.TechRelease) assert.Equal(t, "0001", vers.TechSpLevel) @@ -87,7 +87,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasCVGetPatchLevelExisting) err := vers.constructVersionable("DummyComp", "1.3."+wildCard, *conn, cvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterCV) assert.NoError(t, err) assert.Equal(t, "1", vers.TechRelease) assert.Equal(t, "0003", vers.TechSpLevel) @@ -99,7 +99,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasCVGetPatchLevelNonExisting) err := vers.constructVersionable("DummyComp", "1.3."+wildCard, *conn, cvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterCV) assert.NoError(t, err) assert.Equal(t, "1", vers.TechRelease) assert.Equal(t, "0003", vers.TechSpLevel) @@ -110,7 +110,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasPVGetReleaseExisting) err := vers.constructVersionable("DummyProd", wildCard+".0.0", *conn, pvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterPV) assert.NoError(t, err) assert.Equal(t, "2", vers.TechRelease) assert.Equal(t, "0000", vers.TechSpLevel) @@ -121,7 +121,7 @@ func TestCvResolve(t *testing.T) { mc.AddData(testDataAakaasPVGetReleaseNonExisting) err := vers.constructVersionable("DummyProd", wildCard+".0.0", *conn, pvQueryURL) assert.NoError(t, err) - err = vers.resolveNext() + err = vers.resolveNext(statusFilterPV) assert.NoError(t, err) assert.Equal(t, "1", vers.TechRelease) assert.Equal(t, "0000", vers.TechSpLevel)