mirror of
				https://github.com/fluxcd/flux2.git
				synced 2025-11-04 11:56:11 +08:00 
			
		
		
		
	Add test for annotations
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						Stefan Prodan
					
				
			
			
				
	
			
			
			
						parent
						
							9e76787e9f
						
					
				
				
					commit
					009413affd
				
			@ -23,6 +23,8 @@ import (
 | 
			
		||||
 | 
			
		||||
	"github.com/google/go-containerregistry/pkg/crane"
 | 
			
		||||
	"github.com/google/go-containerregistry/pkg/name"
 | 
			
		||||
	gcrv1 "github.com/google/go-containerregistry/pkg/v1"
 | 
			
		||||
	"github.com/google/go-containerregistry/pkg/v1/mutate"
 | 
			
		||||
	"github.com/google/go-containerregistry/pkg/v1/random"
 | 
			
		||||
	. "github.com/onsi/gomega"
 | 
			
		||||
)
 | 
			
		||||
@ -32,11 +34,18 @@ func Test_List(t *testing.T) {
 | 
			
		||||
	ctx := context.Background()
 | 
			
		||||
	repo := "test-list" + randStringRunes(5)
 | 
			
		||||
	tags := []string{"v0.0.1", "v0.0.2", "v0.0.3"}
 | 
			
		||||
	source := "github.com/fluxcd/fluxv2"
 | 
			
		||||
	rev := "rev"
 | 
			
		||||
	m := Metadata{
 | 
			
		||||
		Source:   source,
 | 
			
		||||
		Revision: rev,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, tag := range tags {
 | 
			
		||||
		dst := fmt.Sprintf("%s/%s:%s", dockerReg, repo, tag)
 | 
			
		||||
		img, err := random.Image(1024, 1)
 | 
			
		||||
		g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		img = mutate.Annotations(img, m.ToAnnotations()).(gcrv1.Image)
 | 
			
		||||
		err = crane.Push(img, dst, craneOptions(ctx)...)
 | 
			
		||||
		g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
	}
 | 
			
		||||
@ -49,5 +58,11 @@ func Test_List(t *testing.T) {
 | 
			
		||||
		tag, err := name.NewTag(meta.URL)
 | 
			
		||||
		g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		g.Expect(tag.TagStr()).Should(BeElementOf(tags))
 | 
			
		||||
 | 
			
		||||
		g.Expect(meta.ToAnnotations()).To(Equal(m.ToAnnotations()))
 | 
			
		||||
 | 
			
		||||
		digest, err := crane.Digest(meta.URL, craneOptions(ctx)...)
 | 
			
		||||
		g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		g.Expect(meta.Digest).To(Equal(digest))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -36,9 +36,10 @@ func Test_Push_Pull(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	url := fmt.Sprintf("%s/%s:%s", dockerReg, repo, tag)
 | 
			
		||||
	metadata := Metadata{
 | 
			
		||||
		Source:   "github.com/fluxcd/fluxv2",
 | 
			
		||||
		Source:   "github.com/fluxcd/flux2",
 | 
			
		||||
		Revision: "rev",
 | 
			
		||||
	}
 | 
			
		||||
	annotations := metadata.ToAnnotations()
 | 
			
		||||
 | 
			
		||||
	testDir := "testdata/build"
 | 
			
		||||
	_, err := Push(ctx, url, testDir, metadata)
 | 
			
		||||
@ -48,6 +49,13 @@ func Test_Push_Pull(t *testing.T) {
 | 
			
		||||
	g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
	g.Expect(len(tags)).To(BeEquivalentTo(1))
 | 
			
		||||
 | 
			
		||||
	image, err := crane.Pull(fmt.Sprintf("%s/%s:%s", dockerReg, repo, tag))
 | 
			
		||||
	g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
 | 
			
		||||
	manifest, err := image.Manifest()
 | 
			
		||||
	g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
	g.Expect(manifest.Annotations).To(BeEquivalentTo(annotations))
 | 
			
		||||
 | 
			
		||||
	tmpDir := t.TempDir()
 | 
			
		||||
	_, err = Pull(ctx, url, tmpDir)
 | 
			
		||||
	g.Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user