Skip to content

Commit 2b13c5d

Browse files
Merge pull request #9938 from jmguzik/network-bindings-initial-tests
Initial network bindings tests
2 parents 8d411a8 + 7ec8760 commit 2b13c5d

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

pkg/bindings/test/networks_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package test_bindings
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"time"
7+
8+
"github.com/containers/podman/v3/pkg/bindings"
9+
"github.com/containers/podman/v3/pkg/bindings/network"
10+
. "github.com/onsi/ginkgo"
11+
. "github.com/onsi/gomega"
12+
"github.com/onsi/gomega/gexec"
13+
)
14+
15+
var _ = Describe("Podman networks", func() {
16+
var (
17+
bt *bindingTest
18+
s *gexec.Session
19+
connText context.Context
20+
err error
21+
)
22+
23+
BeforeEach(func() {
24+
25+
bt = newBindingTest()
26+
bt.RestoreImagesFromCache()
27+
s = bt.startAPIService()
28+
time.Sleep(1 * time.Second)
29+
connText, err = bindings.NewConnection(context.Background(), bt.sock)
30+
Expect(err).To(BeNil())
31+
_, err = network.Prune(connText, &network.PruneOptions{})
32+
Expect(err).To(BeNil())
33+
})
34+
35+
AfterEach(func() {
36+
s.Kill()
37+
bt.cleanup()
38+
})
39+
40+
It("create network", func() {
41+
// create a network with blank config should work
42+
_, err = network.Create(connText, &network.CreateOptions{})
43+
Expect(err).To(BeNil())
44+
45+
name := "foobar"
46+
opts := network.CreateOptions{
47+
Name: &name,
48+
}
49+
50+
report, err := network.Create(connText, &opts)
51+
Expect(err).To(BeNil())
52+
Expect(report.Filename).To(ContainSubstring(name))
53+
54+
// create network with same name should 500
55+
_, err = network.Create(connText, &opts)
56+
Expect(err).ToNot(BeNil())
57+
code, _ := bindings.CheckResponseCode(err)
58+
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
59+
})
60+
61+
It("inspect network", func() {
62+
name := "foobar"
63+
opts := network.CreateOptions{
64+
Name: &name,
65+
}
66+
_, err = network.Create(connText, &opts)
67+
Expect(err).To(BeNil())
68+
data, err := network.Inspect(connText, name, nil)
69+
Expect(err).To(BeNil())
70+
Expect(data[0]["name"]).To(Equal(name))
71+
})
72+
})

0 commit comments

Comments
 (0)