Skip to content

Commit 2c69c4c

Browse files
authored
shorten commits to common length prior compare (#4859)
* shorten commits to common length prior compare * remove obsolete unit tests * some test * 2nd try * fix old wrong unit test
1 parent 09cd271 commit 2c69c4c

2 files changed

+53
-37
lines changed

cmd/abapAddonAssemblyKitReserveNextPackages.go

+38-22
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,53 @@ func checkCommitID(pckgWR []aakaas.PackageWithRepository, i int, checkFailure er
100100
}
101101

102102
func checkCommitIDSameAsGiven(pckgWR []aakaas.PackageWithRepository, i int, checkFailure error) error {
103-
//Ensure for Packages with Status R that CommitID of package = the one from addon.yml, beware of short commitID in addon.yml
104-
addonYAMLcommitIDLength := len(pckgWR[i].Repo.CommitID)
105-
if len(pckgWR[i].Package.CommitID) < addonYAMLcommitIDLength {
106-
checkFailure = errors.New("Provided CommitIDs have wrong length: " + pckgWR[i].Repo.CommitID + "(addon.yml) longer than the one from AAKaaS " + pckgWR[i].Package.CommitID)
107-
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
103+
//Ensure for Packages with Status R that CommitID of package = the one from addon.yml, beware of short commitID in addon.yml (and AAKaaS had due to a bug some time also short commid IDs)
104+
AAKaaSCommitId := pckgWR[i].Package.CommitID
105+
AddonYAMLCommitId := pckgWR[i].Repo.CommitID
106+
107+
var commitIdLength int
108+
//determine shortes commitID length
109+
if len(AAKaaSCommitId) >= len(AddonYAMLCommitId) {
110+
commitIdLength = len(AddonYAMLCommitId)
108111
} else {
109-
packageCommitIDsubsting := pckgWR[i].Package.CommitID[0:addonYAMLcommitIDLength]
110-
if pckgWR[i].Repo.CommitID != packageCommitIDsubsting {
111-
log.Entry().Error("package " + pckgWR[i].Package.PackageName + " was already build but with commit " + pckgWR[i].Package.CommitID + ", not with " + pckgWR[i].Repo.CommitID)
112-
log.Entry().Error("If you want to build a new package make sure to increase the dotted-version-string in addon.yml - current value: " + pckgWR[i].Package.VersionYAML)
113-
log.Entry().Error("If you do NOT want to build a new package enter the commitID " + pckgWR[i].Package.CommitID + " for software component " + pckgWR[i].Repo.Name + " in addon.yml")
114-
checkFailure = errors.New("commit of already released package does not match with addon.yml")
115-
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
116-
}
112+
commitIdLength = len(AAKaaSCommitId)
113+
}
114+
115+
//shorten both to common length
116+
AAKaaSCommitId = AAKaaSCommitId[0:commitIdLength]
117+
AddonYAMLCommitId = AddonYAMLCommitId[0:commitIdLength]
118+
119+
if AddonYAMLCommitId != AAKaaSCommitId {
120+
log.Entry().Error("package " + pckgWR[i].Package.PackageName + " was already build but with commit " + pckgWR[i].Package.CommitID + ", not with " + pckgWR[i].Repo.CommitID)
121+
log.Entry().Error("If you want to build a new package make sure to increase the dotted-version-string in addon.yml - current value: " + pckgWR[i].Package.VersionYAML)
122+
log.Entry().Error("If you do NOT want to build a new package enter the commitID " + pckgWR[i].Package.CommitID + " for software component " + pckgWR[i].Repo.Name + " in addon.yml")
123+
checkFailure = errors.New("commit of already released package does not match with addon.yml")
124+
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
117125
}
118126
return checkFailure
119127
}
120128

121129
func checkCommitIDNotSameAsPrevious(pckgWR []aakaas.PackageWithRepository, i int, checkFailure error) error {
122130
//Check for newly reserved packages which are to be build that CommitID from addon.yml != PreviousCommitID [this will result in an error as no delta can be calculated]
123-
addonYAMLcommitIDLength := len(pckgWR[i].Repo.CommitID)
124-
if len(pckgWR[i].Package.PredecessorCommitID) < addonYAMLcommitIDLength {
125-
checkFailure = errors.New("Provided CommitIDs have wrong length: " + pckgWR[i].Repo.CommitID + "(addon.yml) longer than the one from AAKaaS " + pckgWR[i].Package.CommitID)
126-
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
131+
AAKaaSPreviousCommitId := pckgWR[i].Package.PredecessorCommitID
132+
AddonYAMLCommitId := pckgWR[i].Repo.CommitID
133+
134+
var commitIdLength int
135+
//determine shortes commitID length
136+
if len(AAKaaSPreviousCommitId) >= len(AddonYAMLCommitId) {
137+
commitIdLength = len(AddonYAMLCommitId)
127138
} else {
128-
packagePredecessorCommitIDsubsting := pckgWR[i].Package.PredecessorCommitID[0:addonYAMLcommitIDLength]
129-
if pckgWR[i].Repo.CommitID == packagePredecessorCommitIDsubsting {
130-
checkFailure = errors.New("CommitID of package " + pckgWR[i].Package.PackageName + " is the same as the one of the predecessor package. Make sure to change both the dotted-version-string AND the commitID in addon.yml")
131-
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
132-
}
139+
commitIdLength = len(AAKaaSPreviousCommitId)
133140
}
141+
142+
AAKaaSPreviousCommitId = AAKaaSPreviousCommitId[0:commitIdLength]
143+
AddonYAMLCommitId = AddonYAMLCommitId[0:commitIdLength]
144+
145+
if AddonYAMLCommitId == AAKaaSPreviousCommitId {
146+
checkFailure = errors.New("CommitID of package " + pckgWR[i].Package.PackageName + " is the same as the one of the predecessor package. Make sure to change both the dotted-version-string AND the commitID in addon.yml")
147+
log.Entry().WithError(checkFailure).Error(" => Check failure: to be corrected in addon.yml prior next execution")
148+
}
149+
134150
return checkFailure
135151
}
136152

cmd/abapAddonAssemblyKitReserveNextPackages_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,28 @@ func TestCopyFieldsToRepositoriesPackage(t *testing.T) {
163163
assert.NoError(t, err)
164164
})
165165

166-
t.Run("test copyFieldsToRepositories Planned error with predecessorcommitID same as commitID", func(t *testing.T) {
166+
t.Run("test copyFieldsToRepositories Planned success with predecessorcommitI short AAKaaS", func(t *testing.T) {
167167
pckgWR[0].Package.Status = aakaas.PackageStatusPlanned
168-
pckgWR[0].Package.PredecessorCommitID = pckgWR[0].Repo.CommitID
168+
pckgWR[0].Package.PredecessorCommitID = "predecessor"
169169
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
170170
pckgWR[0].Package.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
171171
_, err := checkAndCopyFieldsToRepositories(pckgWR)
172-
assert.Error(t, err)
172+
assert.NoError(t, err)
173173
})
174174

175-
t.Run("test copyFieldsToRepositories Planned error with too long commitID in addon.yml", func(t *testing.T) {
175+
t.Run("test copyFieldsToRepositories Planned success with predecessorcommitID short addon.yml", func(t *testing.T) {
176176
pckgWR[0].Package.Status = aakaas.PackageStatusPlanned
177-
pckgWR[0].Package.PredecessorCommitID = "something40charslongPREDECESSORyyyyyyyyy"
178-
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxxtoolong"
177+
pckgWR[0].Package.PredecessorCommitID = "predecessor"
178+
pckgWR[0].Repo.CommitID = "successor"
179+
pckgWR[0].Package.CommitID = "successorANDsomemore"
180+
_, err := checkAndCopyFieldsToRepositories(pckgWR)
181+
assert.NoError(t, err)
182+
})
183+
184+
t.Run("test copyFieldsToRepositories Planned error with predecessorcommitID same as commitID", func(t *testing.T) {
185+
pckgWR[0].Package.Status = aakaas.PackageStatusPlanned
186+
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
187+
pckgWR[0].Package.PredecessorCommitID = pckgWR[0].Repo.CommitID
179188
pckgWR[0].Package.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxx"
180189
_, err := checkAndCopyFieldsToRepositories(pckgWR)
181190
assert.Error(t, err)
@@ -198,15 +207,6 @@ func TestCopyFieldsToRepositoriesPackage(t *testing.T) {
198207
_, err := checkAndCopyFieldsToRepositories(pckgWR)
199208
assert.Error(t, err)
200209
})
201-
202-
t.Run("test copyFieldsToRepositories Released error with too long commitID in addon.yml", func(t *testing.T) {
203-
pckgWR[0].Package.Status = aakaas.PackageStatusReleased
204-
pckgWR[0].Package.PredecessorCommitID = "" //released packages do not have this attribute
205-
pckgWR[0].Repo.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxxtoolong"
206-
pckgWR[0].Package.CommitID = "something40charslongxxxxxxxxxxxxxxxxxxxO"
207-
_, err := checkAndCopyFieldsToRepositories(pckgWR)
208-
assert.Error(t, err)
209-
})
210210
}
211211

212212
// ********************* Test reserveNext *******************

0 commit comments

Comments
 (0)