Skip to content

Commit

Permalink
Variable dotted version string fix #2 (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiloKo authored Feb 16, 2023
1 parent eecddf6 commit 9e9b402
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pkg/abap/aakaas/componentVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/abap/aakaas/productVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions pkg/abap/aakaas/testData.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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,
}
25 changes: 13 additions & 12 deletions pkg/abap/aakaas/versionables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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")

Expand Down
16 changes: 8 additions & 8 deletions pkg/abap/aakaas/versionables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 9e9b402

Please sign in to comment.