예제 #1
0
func (s *S) SetUpSuite(c *check.C) {
	s.recover = cmdtest.SetTargetFile(c, []byte("http://localhost"))
	s.recoverToken = cmdtest.SetTokenFile(c, []byte("abc123"))
	if env := os.Getenv("TERM"); env == "" {
		os.Setenv("TERM", "tsuruterm")
	}
}
예제 #2
0
func (s *S) TestShellToContainerWithUnit(c *check.C) {
	guesser := cmdtest.FakeGuesser{Name: "myapp"}
	server := httptest.NewServer(buildHandler([]byte("hello my friend\nglad to see you here\n")))
	defer server.Close()
	target := "http://" + server.Listener.Addr().String()
	targetRecover := cmdtest.SetTargetFile(c, []byte(target))
	defer cmdtest.RollbackFile(targetRecover)
	tokenRecover := cmdtest.SetTokenFile(c, []byte("abc123"))
	defer cmdtest.RollbackFile(tokenRecover)
	var stdout, stderr, stdin bytes.Buffer
	context := Context{
		Args:   []string{"containerid"},
		Stdout: &stdout,
		Stderr: &stderr,
		Stdin:  &stdin,
	}
	var command ShellToContainerCmd
	command.GuessingCommand = GuessingCommand{G: &guesser}
	err := command.Flags().Parse(true, []string{"-a", "myapp"})
	c.Assert(err, check.IsNil)
	manager := NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := NewClient(http.DefaultClient, &context, manager)
	err = command.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "hello my friend\nglad to see you here\n")
}
예제 #3
0
func (s *S) TestShellToContainerCmdConnectionRefused(c *check.C) {
	server := httptest.NewServer(nil)
	addr := server.Listener.Addr().String()
	server.Close()
	targetRecover := cmdtest.SetTargetFile(c, []byte("http://"+addr))
	defer cmdtest.RollbackFile(targetRecover)
	tokenRecover := cmdtest.SetTokenFile(c, []byte("abc123"))
	defer cmdtest.RollbackFile(tokenRecover)
	var buf bytes.Buffer
	context := Context{
		Args:   []string{"af3332d"},
		Stdout: &buf,
		Stderr: &buf,
		Stdin:  &buf,
	}
	var command ShellToContainerCmd
	err := command.Run(&context, nil)
	c.Assert(err, check.NotNil)
}
예제 #4
0
func (s *S) SetUpSuite(c *check.C) {
	s.target = cmdtest.SetTargetFile(c, []byte("http://localhost:8080"))
	s.token = cmdtest.SetTokenFile(c, []byte("sometoken"))
}