github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/bindings/test/manifests_test.go (about)

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