Exemplo n.º 1
0
func (s *discoverySuite) TestNewShellSelectCommandPosix(c *gc.C) {
	if runtime.GOOS == "windows" {
		c.Skip("not supported on windows")
	}

	discoveryScript := service.DiscoverInitSystemScript()
	handler := func(initSystem string) (string, bool) {
		return "echo -n " + initSystem, true
	}
	script := "init_system=$(" + discoveryScript + ")\n"
	// The script will fail with exit 1 if it cannot match in init system.
	script += service.NewShellSelectCommand("init_system", "exit 1", handler)
	commands, filename := s.writeScript(c, "test_shell_select.sh", script)
	commands += "sh " + filename
	response, err := exec.RunCommands(exec.RunParams{
		Commands: script,
	})
	c.Assert(err, jc.ErrorIsNil)

	initSystem, err := service.DiscoverInitSystem()
	c.Assert(err, jc.ErrorIsNil)
	c.Check(response.Code, gc.Equals, 0)
	c.Check(string(response.Stdout), gc.Equals, initSystem)
	c.Check(string(response.Stderr), gc.Equals, "")
}
Exemplo n.º 2
0
func (*serviceSuite) TestListServicesScript(c *gc.C) {
	script := service.ListServicesScript()

	expected := strings.Split(service.DiscoverInitSystemScript(), "\n")
	expected[0] = "init_system=$(" + expected[0]
	expected[len(expected)-1] += ")"
	expected = append(expected,
		`case "$init_system" in`,
		`systemd)`,
		`    /bin/systemctl list-unit-files --no-legend --no-page -t service`+
			` | grep -o -P '^\w[\S]*(?=\.service)'`,
		`    ;;`,
		`upstart)`,
		`    sudo initctl list | awk '{print $1}' | sort | uniq`,
		`    ;;`,
		`*)`,
		`    exit 1`,
		`    ;;`,
		`esac`,
	)
	c.Check(strings.Split(script, "\n"), jc.DeepEquals, expected)
}
Exemplo n.º 3
0
func (s *discoverySuite) newDiscoverInitSystemScript(c *gc.C) (string, string) {
	script := service.DiscoverInitSystemScript()
	return s.writeScript(c, "discover_init_system.sh", script)
}