-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #995 from carolynvs/force-all-tags
Add --force flag to commands that pull tags
- Loading branch information
Showing
17 changed files
with
172 additions
and
11 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
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
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
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
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
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
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
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
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
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
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
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,41 @@ | ||
package cnabtooci | ||
|
||
import ( | ||
"github.com/cnabio/cnab-go/bundle" | ||
"github.com/cnabio/cnab-to-oci/relocation" | ||
) | ||
|
||
var _ RegistryProvider = &TestRegistry{} | ||
|
||
type TestRegistry struct { | ||
MockPullBundle func(tag string, insecureRegistry bool) (bun bundle.Bundle, reloMap *relocation.ImageRelocationMap, err error) | ||
MockPushBundle func(bun bundle.Bundle, tag string, insecureRegistry bool) (reloMap *relocation.ImageRelocationMap, err error) | ||
MockPushInvocationImage func(invocationImage string) (imageDigest string, err error) | ||
} | ||
|
||
func NewTestRegistry() *TestRegistry { | ||
return &TestRegistry{} | ||
} | ||
|
||
func (t TestRegistry) PullBundle(tag string, insecureRegistry bool) (bundle.Bundle, *relocation.ImageRelocationMap, error) { | ||
if t.MockPullBundle != nil { | ||
return t.MockPullBundle(tag, insecureRegistry) | ||
} | ||
|
||
return bundle.Bundle{}, nil, nil | ||
} | ||
|
||
func (t TestRegistry) PushBundle(bun bundle.Bundle, tag string, insecureRegistry bool) (*relocation.ImageRelocationMap, error) { | ||
if t.MockPushBundle != nil { | ||
return t.MockPushBundle(bun, tag, insecureRegistry) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (t TestRegistry) PushInvocationImage(invocationImage string) (string, error) { | ||
if t.MockPushInvocationImage != nil { | ||
return t.MockPushInvocationImage(invocationImage) | ||
} | ||
return "", nil | ||
} |
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
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
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
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
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,98 @@ | ||
package porter | ||
|
||
import ( | ||
"testing" | ||
|
||
"get.porter.sh/porter/pkg/cache" | ||
cnabtooci "get.porter.sh/porter/pkg/cnab/cnab-to-oci" | ||
"get.porter.sh/porter/pkg/config" | ||
"github.com/cnabio/cnab-go/bundle" | ||
"github.com/cnabio/cnab-to-oci/relocation" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBundleResolver_Resolve_ForcePull(t *testing.T) { | ||
tc := config.NewTestConfig(t) | ||
testReg := cnabtooci.NewTestRegistry() | ||
testCache := cache.NewTestCache(cache.New(tc.Config)) | ||
resolver := BundleResolver{ | ||
Cache: testCache, | ||
Registry: testReg, | ||
} | ||
|
||
cacheSearched := false | ||
testCache.FindBundleMock = func(tag string) (cache.CachedBundle, bool, error) { | ||
cacheSearched = true | ||
return cache.CachedBundle{}, true, nil | ||
} | ||
|
||
pulled := false | ||
testReg.MockPullBundle = func(tag string, insecureRegistry bool) (bundle.Bundle, *relocation.ImageRelocationMap, error) { | ||
pulled = true | ||
return bundle.Bundle{}, nil, nil | ||
} | ||
|
||
opts := BundlePullOptions{ | ||
Force: true, | ||
} | ||
resolver.Resolve(opts) | ||
|
||
assert.False(t, cacheSearched, "Force should have skipped the cache") | ||
assert.True(t, pulled, "The bundle should have been re-pulled") | ||
} | ||
|
||
func TestBundleResolver_Resolve_CacheHit(t *testing.T) { | ||
tc := config.NewTestConfig(t) | ||
testReg := cnabtooci.NewTestRegistry() | ||
testCache := cache.NewTestCache(cache.New(tc.Config)) | ||
resolver := BundleResolver{ | ||
Cache: testCache, | ||
Registry: testReg, | ||
} | ||
|
||
cacheSearched := false | ||
testCache.FindBundleMock = func(tag string) (cache.CachedBundle, bool, error) { | ||
cacheSearched = true | ||
return cache.CachedBundle{}, true, nil | ||
} | ||
|
||
pulled := false | ||
testReg.MockPullBundle = func(tag string, insecureRegistry bool) (bundle.Bundle, *relocation.ImageRelocationMap, error) { | ||
pulled = true | ||
return bundle.Bundle{}, nil, nil | ||
} | ||
|
||
opts := BundlePullOptions{} | ||
resolver.Resolve(opts) | ||
|
||
assert.True(t, cacheSearched, "The cache should be searched when force is not specified") | ||
assert.False(t, pulled, "The bundle should NOT be pulled because it was found in the cache") | ||
} | ||
|
||
func TestBundleResolver_Resolve_CacheMiss(t *testing.T) { | ||
tc := config.NewTestConfig(t) | ||
testReg := cnabtooci.NewTestRegistry() | ||
testCache := cache.NewTestCache(cache.New(tc.Config)) | ||
resolver := BundleResolver{ | ||
Cache: testCache, | ||
Registry: testReg, | ||
} | ||
|
||
cacheSearched := false | ||
testCache.FindBundleMock = func(tag string) (cache.CachedBundle, bool, error) { | ||
cacheSearched = true | ||
return cache.CachedBundle{}, false, nil | ||
} | ||
|
||
pulled := false | ||
testReg.MockPullBundle = func(tag string, insecureRegistry bool) (bundle.Bundle, *relocation.ImageRelocationMap, error) { | ||
pulled = true | ||
return bundle.Bundle{}, nil, nil | ||
} | ||
|
||
opts := BundlePullOptions{} | ||
resolver.Resolve(opts) | ||
|
||
assert.True(t, cacheSearched, "The cache should be searched when force is not specified") | ||
assert.True(t, pulled, "The bundle should have been pulled because the bundle was not in the cache") | ||
} |