Skip to content

Commit 57667a1

Browse files
cfergeaupraveenkumar
authored andcommitted
bundle: Check that the bundle URLs match the OpenShift version
Last release we updated the bundle URLs but forgot to change the OpenShift version in Makefile. This new test ensures both are in sync.
1 parent 12b2a36 commit 57667a1

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package bundle
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"testing"
7+
8+
"github.com/crc-org/crc/pkg/crc/preset"
9+
"github.com/crc-org/crc/pkg/crc/version"
10+
11+
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
func TestURIOpenShiftVersion(t *testing.T) {
16+
openshiftVersion := version.GetBundleVersion(preset.OpenShift)
17+
require.NotEqual(t, openshiftVersion, "0.0.0-unset", fmt.Sprintf("OpenShift version is unset (%s), build flags are incorrect", openshiftVersion))
18+
19+
uriPrefix := fmt.Sprintf("https://mirror.openshift.com/pub/openshift-v4/clients/crc/bundles/openshift/%s", openshiftVersion)
20+
for _, osInfo := range bundleLocations {
21+
for _, presetInfo := range osInfo {
22+
for _, remoteFile := range presetInfo {
23+
assert.True(t, strings.HasPrefix(remoteFile.URI, uriPrefix), fmt.Sprintf("URI %s does not match OpenShift version %s", remoteFile.URI, openshiftVersion))
24+
}
25+
}
26+
}
27+
}

pkg/download/download.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ func Download(uri, destination string, mode os.FileMode, sha256sum []byte) (stri
7575
}
7676

7777
type RemoteFile struct {
78-
uri string
78+
URI string
7979
sha256sum string
8080
}
8181

8282
func NewRemoteFile(uri, sha256sum string) *RemoteFile {
8383
return &RemoteFile{
84-
uri: uri,
84+
URI: uri,
8585
sha256sum: sha256sum,
8686
}
8787

@@ -92,15 +92,15 @@ func (r *RemoteFile) Download(bundlePath string, mode os.FileMode) (string, erro
9292
if err != nil {
9393
return "", err
9494
}
95-
return Download(r.uri, bundlePath, mode, sha256)
95+
return Download(r.URI, bundlePath, mode, sha256)
9696
}
9797

9898
func (r *RemoteFile) GetSha256Sum() string {
9999
return r.sha256sum
100100
}
101101

102102
func (r *RemoteFile) GetSourceFilename() (string, error) {
103-
u, err := url.Parse(r.uri)
103+
u, err := url.Parse(r.URI)
104104
if err != nil {
105105
return "", err
106106
}

0 commit comments

Comments
 (0)