Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 7cc7869

Browse files
committed
add test for rename container grpc api
1 parent 3b23e46 commit 7cc7869

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

integration/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (
249249
return resp.ContainerID, nil
250250
}
251251

252+
// RenameContainer renames a container
253+
func (c *HyperClient) RenameContainer(oldName string, newName string) error {
254+
req := types.ContainerRenameRequest{
255+
OldContainerName: oldName,
256+
NewContainerName: newName,
257+
}
258+
_, err := c.client.ContainerRename(c.ctx, &req)
259+
260+
if err != nil {
261+
return err
262+
}
263+
264+
return nil
265+
}
266+
252267
// RemovePod removes a pod by podID
253268
func (c *HyperClient) RemovePod(podID string) error {
254269
_, err := c.client.PodRemove(

integration/hyper_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ func (s *TestSuite) TestCreateContainer(c *C) {
210210
c.Assert(err, IsNil)
211211
}
212212

213+
func (s *TestSuite) TestRenameContainer(c *C) {
214+
err := s.client.PullImage("busybox", "latest", nil)
215+
c.Assert(err, IsNil)
216+
217+
spec := types.UserPod{}
218+
pod, err := s.client.CreatePod(&spec)
219+
c.Assert(err, IsNil)
220+
c.Logf("Pod created: %s", pod)
221+
222+
container, err := s.client.CreateContainer(pod, &types.UserContainer{
223+
Image: "busybox",
224+
})
225+
c.Assert(err, IsNil)
226+
c.Logf("Container created: %s", container)
227+
228+
info, err := s.client.GetContainerInfo(container)
229+
c.Assert(err, IsNil)
230+
231+
oldName := info.Container.Name[1:]
232+
newName := "busybox0123456789"
233+
err = s.client.RenameContainer(oldName, newName)
234+
c.Assert(err, IsNil)
235+
236+
info, err = s.client.GetContainerInfo(container)
237+
c.Assert(err, IsNil)
238+
c.Assert(info.Container.Name[1:], Equals, newName)
239+
240+
err = s.client.RemovePod(pod)
241+
c.Assert(err, IsNil)
242+
}
243+
213244
func (s *TestSuite) TestPullImage(c *C) {
214245
err := s.client.PullImage("alpine", "latest", nil)
215246
c.Assert(err, IsNil)

0 commit comments

Comments
 (0)