aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings/test/manifests_test.go
blob: b93f64b4bacea7e5c7c6b6a43b36f5da8202dabb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package test_bindings

import (
	"net/http"
	"time"

	"github.com/containers/podman/v2/pkg/bindings"
	"github.com/containers/podman/v2/pkg/bindings/images"
	"github.com/containers/podman/v2/pkg/bindings/manifests"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("Podman containers ", func() {
	var (
		bt *bindingTest
		s  *gexec.Session
	)

	BeforeEach(func() {
		bt = newBindingTest()
		bt.RestoreImagesFromCache()
		s = bt.startAPIService()
		time.Sleep(1 * time.Second)
		err := bt.NewConnection()
		Expect(err).To(BeNil())
	})

	AfterEach(func() {
		s.Kill()
		bt.cleanup()
	})

	It("create manifest", func() {
		// create manifest list without images
		id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil)
		Expect(err).To(BeNil())
		list, err := manifests.Inspect(bt.conn, id, nil)
		Expect(err).To(BeNil())
		Expect(len(list.Manifests)).To(BeZero())

		// creating a duplicate should fail as a 500
		_, err = manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil)
		Expect(err).ToNot(BeNil())
		code, _ := bindings.CheckResponseCode(err)
		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))

		_, errs := images.Remove(bt.conn, []string{id}, nil)
		Expect(len(errs)).To(BeZero())

		// create manifest list with images
		id, err = manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil)
		Expect(err).To(BeNil())
		list, err = manifests.Inspect(bt.conn, id, nil)
		Expect(err).To(BeNil())
		Expect(len(list.Manifests)).To(BeNumerically("==", 1))
	})

	It("inspect bogus manifest", func() {
		_, err := manifests.Inspect(bt.conn, "larry", nil)
		Expect(err).ToNot(BeNil())
		code, _ := bindings.CheckResponseCode(err)
		Expect(code).To(BeNumerically("==", http.StatusNotFound))
	})

	It("add manifest", func() {
		// add to bogus should 404
		_, err := manifests.Add(bt.conn, "foobar", nil)
		Expect(err).ToNot(BeNil())
		code, _ := bindings.CheckResponseCode(err)
		Expect(code).To(BeNumerically("==", http.StatusNotFound))

		id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil)
		Expect(err).To(BeNil())
		options := new(manifests.AddOptions).WithImages([]string{alpine.name})
		_, err = manifests.Add(bt.conn, id, options)
		Expect(err).To(BeNil())
		list, err := manifests.Inspect(bt.conn, id, nil)
		Expect(err).To(BeNil())
		Expect(len(list.Manifests)).To(BeNumerically("==", 1))

		// add bogus name to existing list should fail
		options.WithImages([]string{"larry"})
		_, err = manifests.Add(bt.conn, id, options)
		Expect(err).ToNot(BeNil())
		code, _ = bindings.CheckResponseCode(err)
		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
	})

	It("remove manifest", func() {
		// removal on bogus manifest list should be 404
		_, err := manifests.Remove(bt.conn, "larry", "1234", nil)
		Expect(err).ToNot(BeNil())
		code, _ := bindings.CheckResponseCode(err)
		Expect(code).To(BeNumerically("==", http.StatusNotFound))

		id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil)
		Expect(err).To(BeNil())
		data, err := manifests.Inspect(bt.conn, id, nil)
		Expect(err).To(BeNil())
		Expect(len(data.Manifests)).To(BeNumerically("==", 1))

		// removal on a good manifest list with a bad digest should be 400
		_, err = manifests.Remove(bt.conn, id, "!234", nil)
		Expect(err).ToNot(BeNil())
		code, _ = bindings.CheckResponseCode(err)
		Expect(code).To(BeNumerically("==", http.StatusBadRequest))

		digest := data.Manifests[0].Digest.String()
		_, err = manifests.Remove(bt.conn, id, digest, nil)
		Expect(err).To(BeNil())

		// removal on good manifest with good digest should work
		data, err = manifests.Inspect(bt.conn, id, nil)
		Expect(err).To(BeNil())
		Expect(len(data.Manifests)).To(BeZero())
	})

	// There is NO annotate endpoint, this could never work.:w

	//It("annotate manifest", func() {
	//	id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil)
	//	Expect(err).To(BeNil())
	//	opts := image.ManifestAddOpts{Images: []string{"docker.io/library/alpine:latest"}}
	//
	//	_, err = manifests.Add(bt.conn, id, opts)
	//	Expect(err).To(BeNil())
	//	data, err := manifests.Inspect(bt.conn, id)
	//	Expect(err).To(BeNil())
	//	Expect(len(data.Manifests)).To(BeNumerically("==", 1))
	//	digest := data.Manifests[0].Digest.String()
	//	annoOpts := image.ManifestAnnotateOpts{OS: "foo"}
	//	_, err = manifests.Annotate(bt.conn, id, digest, annoOpts)
	//	Expect(err).To(BeNil())
	//	list, err := manifests.Inspect(bt.conn, id)
	//	Expect(err).To(BeNil())
	//	Expect(len(list.Manifests)).To(BeNumerically("==", 1))
	//	Expect(list.Manifests[0].Platform.OS).To(Equal("foo"))
	//})

	It("push manifest", func() {
		Skip("TODO")
	})
})