-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage of the runtime assets package (#628)
* Increases coverage to 88.2%. * Introduce a fake registry to test crane against. Fixes #619 Signed-off-by: Brad P. Crochet <[email protected]>
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package runtime | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http/httptest" | ||
"net/url" | ||
|
||
"github.com/google/go-containerregistry/pkg/crane" | ||
"github.com/google/go-containerregistry/pkg/registry" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
"github.com/google/go-containerregistry/pkg/v1/random" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var _ = Describe("Runtime assets tests", func() { | ||
var src, srcHost string | ||
var digest v1.Hash | ||
BeforeEach(func() { | ||
// Set up a fake registry. | ||
s := httptest.NewServer(registry.New()) | ||
DeferCleanup(func() { | ||
s.Close() | ||
}) | ||
u, err := url.Parse(s.URL) | ||
Expect(err).ToNot(HaveOccurred()) | ||
src = fmt.Sprintf("%s/test/preflight", u.Host) | ||
srcHost = u.Hostname() | ||
|
||
img, err := random.Image(1024, 5) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
digest, err = img.Digest() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = crane.Push(img, src) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
images["assettest"] = fmt.Sprintf("%s:latest", src) | ||
}) | ||
Context("when asking for assets", func() { | ||
Context("the registry works", func() { | ||
It("should return a digest list", func() { | ||
data := Assets(context.TODO()) | ||
Expect(data.Images).To(ContainElement(fmt.Sprintf("%s@%s", srcHost, digest.String()))) | ||
}) | ||
}) | ||
Context("the registry throws an error", func() { | ||
It("should not return the image", func() { | ||
data := Assets(context.TODO()) | ||
Expect(data.Images).ToNot(ContainElement("quay.io/operator-framework/scorecard-test@sha256:deadb33f")) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
var _ = Describe("Scorecard Image tests", func() { | ||
Context("when getting the Scorecard image", func() { | ||
Context("the default is used", func() { | ||
It("should return the default", func() { | ||
image := ScorecardImage() | ||
Expect(image).To(Equal(images["scorecard"])) | ||
}) | ||
}) | ||
Context("the image is overriden", func() { | ||
It("should return the passed param", func() { | ||
viper.Set("scorecard_image", "quay.io/some/container:v1.0.0") | ||
image := ScorecardImage() | ||
Expect(image).To(Equal("quay.io/some/container:v1.0.0")) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package runtime | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2/dsl/core" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestBundle(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Runtime Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package runtime | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Runtime tests", func() { | ||
Context("when the cluster version is unknown", func() { | ||
It("will get unknown/unknown in the version struct", func() { | ||
version := UnknownOpenshiftClusterVersion() | ||
Expect(version.Name).To(Equal("unknown")) | ||
Expect(version.Version).To(Equal("unknown")) | ||
}) | ||
}) | ||
}) |