func (b *CommandBuilder) SetupVeth( containerNS namespace.Namespace, sandboxLinkName string, containerLinkName string, address net.IPNet, sandboxName string, routeCommand executor.Command, ) executor.Command { return commands.InNamespace{ Namespace: containerNS, Command: commands.Group( append( []executor.Command{ commands.CreateVeth{ Name: containerLinkName, PeerName: sandboxLinkName, MTU: 1450, }, commands.MoveLink{ Name: sandboxLinkName, SandboxName: sandboxName, }, commands.AddAddress{ InterfaceName: containerLinkName, Address: address, }, commands.SetLinkUp{ LinkName: containerLinkName, }, }, routeCommand, ), ), } }
Describe("String", func() { var cmdStr string It("renders the list of commands in the group", func() { all.Execute(context) cmdStr = all.String() Expect(cmdStr).To(Equal("(\n" + " some-command 1 &&\n" + " some-command 2 &&\n" + " some-command 3\n" + ")")) }) Context("when the command group is empty", func() { It("prints as two braces", func() { all = commands.Group([]executor.Command{}) Expect(all.String()).To(Equal("(\n)")) }) }) Context("when there are nested commands", func() { It("indents the nested group with braces", func() { all = commands.All(commands.All(command1, command2), command3) all.Execute(context) cmdStr = all.String() Expect(cmdStr).To(Equal("(\n" + " (\n" + " some-command 1 &&\n" + " some-command 2\n" + " ) &&\n" + " some-command 3\n" +
Expect(cmd).To(Equal( commands.InNamespace{ Namespace: containerNS, Command: commands.Group( append( []executor.Command{ commands.CreateVeth{ Name: "container-veth", PeerName: "sandbox-veth", MTU: 1450, }, commands.MoveLink{ Name: "sandbox-veth", SandboxName: "some-sandbox-name", }, commands.AddAddress{ InterfaceName: "container-veth", Address: address, }, commands.SetLinkUp{ LinkName: "container-veth", }, }, routeCommand, ), ), }, )) }) })