aboutsummaryrefslogtreecommitdiff
path: root/test/e2e/system_connection_test.go
blob: a23d50f299f083f91b88d22d08b75616ed00a99a (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package integration

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/containers/common/pkg/config"
	. "github.com/containers/podman/v2/test/utils"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman system connection", func() {
	ConfPath := struct {
		Value string
		IsSet bool
	}{}

	var (
		podmanTest *PodmanTestIntegration
	)

	BeforeEach(func() {
		ConfPath.Value, ConfPath.IsSet = os.LookupEnv("CONTAINERS_CONF")
		conf, err := ioutil.TempFile("", "containersconf")
		if err != nil {
			panic(err)
		}
		os.Setenv("CONTAINERS_CONF", conf.Name())

		tempdir, err := CreateTempDirInTempDir()
		if err != nil {
			panic(err)
		}
		podmanTest = PodmanTestCreate(tempdir)
		podmanTest.Setup()
	})

	AfterEach(func() {
		podmanTest.Cleanup()
		os.Remove(os.Getenv("CONTAINERS_CONF"))
		if ConfPath.IsSet {
			os.Setenv("CONTAINERS_CONF", ConfPath.Value)
		} else {
			os.Unsetenv("CONTAINERS_CONF")
		}

		f := CurrentGinkgoTestDescription()
		timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds())
		GinkgoWriter.Write([]byte(timedResult))
	})

	It("add", func() {
		cmd := []string{"system", "connection", "add",
			"--default",
			"--identity", "~/.ssh/id_rsa",
			"QA",
			"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
		}
		session := podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).Should(Exit(0))
		Expect(session.Out).Should(Say(""))

		cfg, err := config.ReadCustomConfig()
		Expect(err).ShouldNot(HaveOccurred())
		Expect(cfg.Engine.ActiveService).To(Equal("QA"))
		Expect(cfg.Engine.ServiceDestinations["QA"]).To(Equal(
			config.Destination{
				URI:      "ssh://root@server.fubar.com:2222/run/podman/podman.sock",
				Identity: "~/.ssh/id_rsa",
			},
		))

		cmd = []string{"system", "connection", "rename",
			"QA",
			"QE",
		}
		session = podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).Should(Exit(0))

		cfg, err = config.ReadCustomConfig()
		Expect(err).ShouldNot(HaveOccurred())
		Expect(cfg.Engine.ActiveService).To(Equal("QE"))
		Expect(cfg.Engine.ServiceDestinations["QE"]).To(Equal(
			config.Destination{
				URI:      "ssh://root@server.fubar.com:2222/run/podman/podman.sock",
				Identity: "~/.ssh/id_rsa",
			},
		))
	})

	It("remove", func() {
		cmd := []string{"system", "connection", "add",
			"--default",
			"--identity", "~/.ssh/id_rsa",
			"QA",
			"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
		}
		session := podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).Should(Exit(0))

		for i := 0; i < 2; i++ {
			cmd = []string{"system", "connection", "remove", "QA"}
			session = podmanTest.Podman(cmd)
			session.WaitWithDefaultTimeout()
			Expect(session).Should(Exit(0))
			Expect(session.Out).Should(Say(""))

			cfg, err := config.ReadCustomConfig()
			Expect(err).ShouldNot(HaveOccurred())
			Expect(cfg.Engine.ActiveService).To(BeEmpty())
			Expect(cfg.Engine.ServiceDestinations).To(BeEmpty())
		}
	})

	It("default", func() {
		for _, name := range []string{"devl", "qe"} {
			cmd := []string{"system", "connection", "add",
				"--default",
				"--identity", "~/.ssh/id_rsa",
				name,
				"ssh://root@server.fubar.com:2222/run/podman/podman.sock",
			}
			session := podmanTest.Podman(cmd)
			session.WaitWithDefaultTimeout()
			Expect(session).Should(Exit(0))
		}

		cmd := []string{"system", "connection", "default", "devl"}
		session := podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).Should(Exit(0))
		Expect(session.Out).Should(Say(""))

		cfg, err := config.ReadCustomConfig()
		Expect(err).ShouldNot(HaveOccurred())
		Expect(cfg.Engine.ActiveService).To(Equal("devl"))

		cmd = []string{"system", "connection", "list"}
		session = podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).Should(Exit(0))
		Expect(session.Out).Should(Say("Name *Identity *URI"))
	})

	It("failed default", func() {
		cmd := []string{"system", "connection", "default", "devl"}
		session := podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).ShouldNot(Exit(0))
		Expect(session.Err).Should(Say("destination is not defined"))
	})

	It("failed rename", func() {
		cmd := []string{"system", "connection", "rename", "devl", "QE"}
		session := podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).ShouldNot(Exit(0))
		Expect(session.Err).Should(Say("destination is not defined"))
	})

	It("empty list", func() {
		cmd := []string{"system", "connection", "list"}
		session := podmanTest.Podman(cmd)
		session.WaitWithDefaultTimeout()
		Expect(session).Should(Exit(0))
		Expect(session.Out).Should(Say(""))
		Expect(session.Err).Should(Say(""))
	})
})