Skip to content

Commit

Permalink
gen-manifests: create predictable version/release numbers in mockDeps…
Browse files Browse the repository at this point in the history
…olve

The current code will only generate "0" version numbers for packages
and releases. This limits the usefulness of this mock in the tests
for otk. Instead generate predictable but (mostly) non-zero numbers
based on the modulo of the first and second char of the pkgname.
  • Loading branch information
mvo5 committed Sep 16, 2024
1 parent fa40f2d commit 9a4ac5f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/gobwas/glob"
Expand Down Expand Up @@ -375,11 +376,15 @@ func mockDepsolve(packageSets map[string][]rpmmd.PackageSet, repos []rpmmd.RepoC
for _, pkgSet := range pkgSetChain {
for _, pkgName := range pkgSet.Include {
checksum := fmt.Sprintf("%x", sha256.Sum256([]byte(pkgName)))
// generate predictable but non-empty
// release/version numbers
ver := strconv.Itoa(int(pkgName[0]) % 9)
rel := strconv.Itoa(int(pkgName[1]) % 9)
spec := rpmmd.PackageSpec{
Name: pkgName,
Epoch: 0,
Version: "0",
Release: "0",
Version: ver,
Release: "r" + rel,
Arch: "noarch",
RemoteLocation: fmt.Sprintf("https://example.com/repo/packages/%s", pkgName),
Checksum: "sha256:" + checksum,
Expand Down

0 comments on commit 9a4ac5f

Please sign in to comment.