github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/bindings/test/manifests_test.go (about)

     1  package bindings_test
     2  
     3  import (
     4  	"net/http"
     5  	"time"
     6  
     7  	"github.com/hanks177/podman/v4/pkg/bindings"
     8  	"github.com/hanks177/podman/v4/pkg/bindings/images"
     9  	"github.com/hanks177/podman/v4/pkg/bindings/manifests"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	"github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("podman manifest", func() {
    16  	var (
    17  		bt *bindingTest
    18  		s  *gexec.Session
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		bt = newBindingTest()
    23  		bt.RestoreImagesFromCache()
    24  		s = bt.startAPIService()
    25  		time.Sleep(1 * time.Second)
    26  		err := bt.NewConnection()
    27  		Expect(err).ToNot(HaveOccurred())
    28  
    29  	})
    30  
    31  	AfterEach(func() {
    32  		s.Kill()
    33  		bt.cleanup()
    34  	})
    35  
    36  	It("create", func() {
    37  		// create manifest list without images
    38  		id, err := manifests.Create(bt.conn, "quay.io/libpod/foobar:latest", []string{}, nil)
    39  		Expect(err).ToNot(HaveOccurred(), err)
    40  		list, err := manifests.Inspect(bt.conn, id, nil)
    41  		Expect(err).ToNot(HaveOccurred())
    42  
    43  		Expect(len(list.Manifests)).To(BeZero())
    44  
    45  		// creating a duplicate should fail as a 500
    46  		_, err = manifests.Create(bt.conn, "quay.io/libpod/foobar:latest", nil, nil)
    47  		Expect(err).To(HaveOccurred())
    48  
    49  		code, _ := bindings.CheckResponseCode(err)
    50  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
    51  
    52  		_, errs := images.Remove(bt.conn, []string{id}, nil)
    53  		Expect(len(errs)).To(BeZero())
    54  
    55  		// create manifest list with images
    56  		id, err = manifests.Create(bt.conn, "quay.io/libpod/foobar:latest", []string{alpine.name}, nil)
    57  		Expect(err).ToNot(HaveOccurred())
    58  
    59  		list, err = manifests.Inspect(bt.conn, id, nil)
    60  		Expect(err).ToNot(HaveOccurred())
    61  
    62  		Expect(len(list.Manifests)).To(BeNumerically("==", 1))
    63  	})
    64  
    65  	It("inspect", func() {
    66  		_, err := manifests.Inspect(bt.conn, "larry", nil)
    67  		Expect(err).To(HaveOccurred())
    68  
    69  		code, _ := bindings.CheckResponseCode(err)
    70  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
    71  	})
    72  
    73  	It("add", func() {
    74  		// add to bogus should 404
    75  		_, err := manifests.Add(bt.conn, "foobar", nil)
    76  		Expect(err).To(HaveOccurred())
    77  
    78  		code, _ := bindings.CheckResponseCode(err)
    79  		Expect(code).To(BeNumerically("==", http.StatusNotFound), err.Error())
    80  
    81  		id, err := manifests.Create(bt.conn, "quay.io/libpod/foobar:latest", []string{}, nil)
    82  		Expect(err).ToNot(HaveOccurred())
    83  
    84  		options := new(manifests.AddOptions).WithImages([]string{alpine.name})
    85  		_, err = manifests.Add(bt.conn, id, options)
    86  		Expect(err).ToNot(HaveOccurred())
    87  
    88  		list, err := manifests.Inspect(bt.conn, id, nil)
    89  		Expect(err).ToNot(HaveOccurred())
    90  
    91  		Expect(len(list.Manifests)).To(BeNumerically("==", 1))
    92  
    93  		// add bogus name to existing list should fail
    94  		options.WithImages([]string{"larry"})
    95  		_, err = manifests.Add(bt.conn, id, options)
    96  		Expect(err).To(HaveOccurred())
    97  
    98  		code, _ = bindings.CheckResponseCode(err)
    99  		Expect(code).To(BeNumerically("==", http.StatusBadRequest))
   100  	})
   101  
   102  	It("remove digest", func() {
   103  		// removal on bogus manifest list should be 404
   104  		_, err := manifests.Remove(bt.conn, "larry", "1234", nil)
   105  		Expect(err).To(HaveOccurred())
   106  
   107  		code, _ := bindings.CheckResponseCode(err)
   108  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   109  
   110  		id, err := manifests.Create(bt.conn, "quay.io/libpod/foobar:latest", []string{alpine.name}, nil)
   111  		Expect(err).ToNot(HaveOccurred())
   112  
   113  		data, err := manifests.Inspect(bt.conn, id, nil)
   114  		Expect(err).ToNot(HaveOccurred())
   115  
   116  		Expect(len(data.Manifests)).To(BeNumerically("==", 1))
   117  
   118  		// removal on a good manifest list with a bad digest should be 400
   119  		_, err = manifests.Remove(bt.conn, id, "!234", nil)
   120  		Expect(err).To(HaveOccurred())
   121  
   122  		code, _ = bindings.CheckResponseCode(err)
   123  		Expect(code).To(BeNumerically("==", http.StatusBadRequest))
   124  
   125  		digest := data.Manifests[0].Digest.String()
   126  		_, err = manifests.Remove(bt.conn, id, digest, nil)
   127  		Expect(err).ToNot(HaveOccurred())
   128  
   129  		// removal on good manifest with good digest should work
   130  		data, err = manifests.Inspect(bt.conn, id, nil)
   131  		Expect(err).ToNot(HaveOccurred())
   132  
   133  		Expect(data.Manifests).Should(BeEmpty())
   134  	})
   135  
   136  	It("annotate", func() {
   137  		id, err := manifests.Create(bt.conn, "quay.io/libpod/foobar:latest", []string{}, nil)
   138  		Expect(err).ToNot(HaveOccurred())
   139  
   140  		opts := manifests.AddOptions{Images: []string{"quay.io/libpod/alpine:latest"}}
   141  
   142  		_, err = manifests.Add(bt.conn, id, &opts)
   143  		Expect(err).ToNot(HaveOccurred())
   144  
   145  		data, err := manifests.Inspect(bt.conn, id, nil)
   146  		Expect(err).ToNot(HaveOccurred())
   147  
   148  		Expect(len(data.Manifests)).To(BeNumerically("==", 1))
   149  
   150  		digest := data.Manifests[0].Digest.String()
   151  		annoOpts := new(manifests.ModifyOptions).WithOS("foo")
   152  		_, err = manifests.Annotate(bt.conn, id, []string{digest}, annoOpts)
   153  		Expect(err).ToNot(HaveOccurred())
   154  
   155  		list, err := manifests.Inspect(bt.conn, id, nil)
   156  		Expect(err).ToNot(HaveOccurred())
   157  
   158  		Expect(len(list.Manifests)).To(BeNumerically("==", 1))
   159  		Expect(list.Manifests[0].Platform.OS).To(Equal("foo"))
   160  	})
   161  
   162  	It("push manifest", func() {
   163  		Skip("TODO: implement test for manifest push to registry")
   164  	})
   165  })