Skip to content

Commit

Permalink
Minor test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 committed Apr 24, 2024
1 parent 13462f7 commit 8b20d49
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions agent/engine/engine_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,58 +642,55 @@ func TestManifestPulledDoesNotDependOnContainerOrdering(t *testing.T) {
// The test depends on 127.0.0.1:51670/busybox image that is prepared by `make test-registry`
// command.
func TestPullContainerManifestInteg(t *testing.T) {
allPullBehaviors := []config.ImagePullBehaviorType{
config.ImagePullDefaultBehavior, config.ImagePullAlwaysBehavior,
config.ImagePullOnceBehavior, config.ImagePullPreferCachedBehavior,
}
tcs := []struct {
name string
image string
setConfig func(c *config.Config)
pullBehaviorsToSkip map[config.ImagePullBehaviorType]string
assertError func(t *testing.T, err error)
name string
image string
setConfig func(c *config.Config)
imagePullBehaviors []config.ImagePullBehaviorType
assertError func(t *testing.T, err error)
}{
{
name: "digest available in image reference",
image: "ubuntu@sha256:c3839dd800b9eb7603340509769c43e146a74c63dca3045a8e7dc8ee07e53966",
name: "digest available in image reference",
image: "ubuntu@sha256:c3839dd800b9eb7603340509769c43e146a74c63dca3045a8e7dc8ee07e53966",
imagePullBehaviors: allPullBehaviors,
},
{
name: "digest can be resolved from explicit tag",
image: "127.0.0.1:51670/busybox:latest",
name: "digest can be resolved from explicit tag",
image: "127.0.0.1:51670/busybox:latest",
imagePullBehaviors: allPullBehaviors,
},
{
name: "digest can be resolved without an explicit tag",
image: "127.0.0.1:51670/busybox",
name: "digest can be resolved without an explicit tag",
image: "127.0.0.1:51670/busybox",
imagePullBehaviors: allPullBehaviors,
},
{
name: "manifest pull can timeout",
image: "127.0.0.1:51670/busybox",
setConfig: func(c *config.Config) { c.ManifestPullTimeout = 0 },
pullBehaviorsToSkip: map[config.ImagePullBehaviorType]string{
config.ImagePullPreferCachedBehavior: "",
},
name: "manifest pull can timeout",
image: "127.0.0.1:51670/busybox",
setConfig: func(c *config.Config) { c.ManifestPullTimeout = 0 },
imagePullBehaviors: []config.ImagePullBehaviorType{config.ImagePullAlwaysBehavior},

assertError: func(t *testing.T, err error) {
assert.ErrorContains(t, err, "Could not transition to MANIFEST_PULLED; timed out")
},
},
{
name: "manifest pull can timeout - non-zero timeout",
image: "127.0.0.1:51670/busybox",
setConfig: func(c *config.Config) { c.ManifestPullTimeout = 100 * time.Microsecond },
pullBehaviorsToSkip: map[config.ImagePullBehaviorType]string{
config.ImagePullPreferCachedBehavior: "",
},
name: "manifest pull can timeout - non-zero timeout",
image: "127.0.0.1:51670/busybox",
setConfig: func(c *config.Config) { c.ManifestPullTimeout = 100 * time.Microsecond },
imagePullBehaviors: []config.ImagePullBehaviorType{config.ImagePullAlwaysBehavior},
assertError: func(t *testing.T, err error) {
assert.ErrorContains(t, err, "Could not transition to MANIFEST_PULLED; timed out")
},
},
}
imagePullBehaviors := []config.ImagePullBehaviorType{
config.ImagePullDefaultBehavior, config.ImagePullAlwaysBehavior,
config.ImagePullOnceBehavior, config.ImagePullPreferCachedBehavior,
}
for _, tc := range tcs {
for _, imagePullBehavior := range imagePullBehaviors {
if _, ok := tc.pullBehaviorsToSkip[imagePullBehavior]; ok {
continue
}
t.Run(fmt.Sprintf("%s - %d", tc.name, imagePullBehavior), func(t *testing.T) {
for _, imagePullBehavior := range tc.imagePullBehaviors {
t.Run(fmt.Sprintf("%s - %v", tc.name, imagePullBehavior), func(t *testing.T) {
cfg := defaultTestConfigIntegTest()
cfg.ImagePullBehavior = imagePullBehavior

Expand Down

0 comments on commit 8b20d49

Please sign in to comment.