func (s *AdapterSuite) TestCompleteFlow(c *C) { var cmd *client.Command var err error var result *client.CommandResult if os.Getenv("CHANGES") == "1" { c.ExpectFailure("For as yet unknown reasons, container initialization fails on Changes.") } clientLog := client.NewLog() adapter, err := adapter.Get("lxc") c.Assert(err, IsNil) wg := sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() s.reportLogChunks(clientLog) }() config := &client.Config{} config.JobstepID = containerName err = adapter.Init(config) c.Assert(err, IsNil) err = adapter.Prepare(clientLog) c.Assert(err, IsNil) defer adapter.Shutdown(clientLog) cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho hello > foo.txt\nexit 0") c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(string(result.Output), Equals, "") c.Assert(result.Success, Equals, true) cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho $HOME\nexit 0") cmd.CaptureOutput = true c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(string(result.Output), Equals, "/home/ubuntu\n") c.Assert(result.Success, Equals, true) cmd, err = client.NewCommand("test", "#!/bin/bash -e\ndd if=/dev/zero of=test.img bs=1M count=10 && mkfs.ext4 -b 1024 -j -F test.img && sudo mount -v -o loop test.img /mnt") cmd.CaptureOutput = true c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(result.Success, Equals, true) // test with a command that expects stdin cmd, err = client.NewCommand("test", "#!/bin/bash -e\nread foo\nexit 1") c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(string(result.Output), Equals, "") c.Assert(result.Success, Equals, false) artifacts, err := adapter.CollectArtifacts([]string{"foo.txt"}, clientLog) c.Assert(err, IsNil) c.Assert(len(artifacts), Equals, 1) c.Assert(artifacts[0], Matches, ".*/home/ubuntu/foo.txt") clientLog.Close() wg.Wait() }
func (s *AdapterSuite) TestCompleteFlow(c *C) { var cmd *client.Command var err error var result *client.CommandResult clientLog := client.NewLog() adapter, err := adapter.Get("lxc") c.Assert(err, IsNil) wg := sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() s.reportLogChunks(clientLog) }() config := &client.Config{} config.JobstepID = containerName err = adapter.Init(config) c.Assert(err, IsNil) err = adapter.Prepare(clientLog) c.Assert(err, IsNil) defer adapter.Shutdown(clientLog) cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho hello > foo.txt\nexit 0") c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(string(result.Output), Equals, "") c.Assert(result.Success, Equals, true) cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho $HOME\nexit 0") cmd.CaptureOutput = true c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(string(result.Output), Equals, "/home/ubuntu\n") c.Assert(result.Success, Equals, true) // test with a command that expects stdin cmd, err = client.NewCommand("test", "#!/bin/bash -e\nread foo\nexit 1") c.Assert(err, IsNil) result, err = adapter.Run(cmd, clientLog) c.Assert(err, IsNil) c.Assert(string(result.Output), Equals, "") c.Assert(result.Success, Equals, false) artifacts, err := adapter.CollectArtifacts([]string{"foo.txt"}, clientLog) c.Assert(err, IsNil) c.Assert(len(artifacts), Equals, 1) c.Assert(artifacts[0], Matches, ".*/home/ubuntu/foo.txt") clientLog.Close() wg.Wait() }