コード例 #1
0
func TestIrregular_RemexecPs1NotExists(t *testing.T) {
	scriptName := filepath.Join(baseDir, "remexec.ps1")
	tmpScriptName := filepath.Join(baseDir, "remexec.ps1.tmp")

	os.Rename(scriptName, tmpScriptName)
	defer os.Rename(tmpScriptName, scriptName)

	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeRemoteCommand("pwd")
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}

	if rc != 255 {
		t.Errorf("RC => %d, wants %d", rc, 255)
	}

	if strings.Contains(output, "REX003E") {
		t.Errorf("Output contains unexpected error message.")
		t.Log("Output:")
		t.Log(output)
	}
}
コード例 #2
0
func TestLocalScript(t *testing.T) {
	scriptPath := filepath.Join(baseDir, "localtest.sh")

	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeLocalScript(scriptPath + ` "test1" "test2"`)
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 23 {
		t.Errorf("RC => %d, wants %d", rc, 23)
	}

	matcher := regexp.MustCompile(`script=/home/keyuser/tmp/\d{14}\.\d{3}\.localtest\.sh`)
	if !matcher.MatchString(output) {
		t.Errorf("Output does not contains correct script value.")
		t.Log("Output:")
		t.Log(output)
	}
	if !strings.Contains(output, "param1=test1") {
		t.Errorf("Output does not contains correct first parameter value.")
		t.Log("Output:")
		t.Log(output)
	}
	if !strings.Contains(output, "param2=test2") {
		t.Errorf("Output does not contains correct second parameter value.")
		t.Log("Output:")
		t.Log(output)
	}
}
コード例 #3
0
func TestRemote_Script(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeRemoteCommand(`/home/passuser/test.sh "test1" "test2"`)
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 12 {
		t.Errorf("RC => %d, wants %d", rc, 12)
	}
	if !strings.Contains(output, "script=/home/passuser/test.sh") {
		t.Errorf("Output does not contains correct script value.")
		t.Log("Output:")
		t.Log(output)
	}
	if !strings.Contains(output, "param1=test1") {
		t.Errorf("Output does not contains correct first parameter value.")
		t.Log("Output:")
		t.Log(output)
	}
	if !strings.Contains(output, "param2=test2") {
		t.Errorf("Output does not contains correct second parameter value.")
		t.Log("Output:")
		t.Log(output)
	}
}
コード例 #4
0
func TestIrregular_LocalScriptNotExists(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeLocalScript("noexistscript")
	c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 0 {
		t.Errorf("RC => %d, wants %d", rc, 0)
	}
}
コード例 #5
0
func TestIrregular_WrongPassword(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeWithConfig(filepath.Join(baseDir, "wrongpass.ini"))
	c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 255 {
		t.Errorf("RC => %d, wants %d", rc, 255)
	}
}
コード例 #6
0
func TestRemote_Command_WithParameter(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeRemoteCommand(`echo testmessage`)
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 0 {
		t.Errorf("RC => %d, wants %d", rc, 0)
	}
	output = strings.Trim(output, "\r\n")
	if output != "testmessage" {
		t.Errorf("Output => %s, wants %s.", output, "testmessage")
	}
}
コード例 #7
0
func TestRemote_Command_NoParameter(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeRemoteCommand("pwd")
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 0 {
		t.Errorf("RC => %d, wants %d", rc, 0)
	}
	if !strings.HasPrefix(output, "/") {
		t.Errorf("Output is not expected format.")
		t.Errorf("Output: %s", output)
	}
}
コード例 #8
0
func TestIrregular_RemoteCommandNotExists(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeRemoteCommand("noexistcommand")
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 255 {
		t.Errorf("RC => %d, wants %d", rc, 255)
	}
	if strings.Contains(output, "REX003E") {
		t.Errorf("Output contains unexpected error message.")
		t.Log("Output:")
		t.Log(output)
	}
}
コード例 #9
0
func TestIrregular_ConfigFileNotExists(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeWithConfig(filepath.Join(baseDir, "noexistconfig.ini"))
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 255 {
		t.Errorf("RC => %d, wants %d", rc, 255)
	}
	if !strings.Contains(output, "REX002E") {
		t.Errorf("Output does not contains expected error message.")
		t.Log("Output:")
		t.Log(output)
	}
}
コード例 #10
0
func TestIrregular_LocalScriptNotExists(t *testing.T) {
	c := capturer.NewStdoutCapturer()
	c.Start()
	rc, err := executeLocalScript("noexistscript")
	output := c.Stop()

	if err != nil {
		t.Fatalf("Error occured: %s", err)
	}
	if rc != 255 {
		t.Errorf("RC => %d, wants %d", rc, 255)
	}
	if !strings.Contains(output, "REX003E") {
		t.Errorf("Output does not contains expected error message.")
		t.Log("Output:")
		t.Log(output)
	}
}