Ejemplo n.º 1
0
// all the interactions are dispatched with this function
func doInteraction(c *check.C, resource, verb string, interaction apiInteraction) {
	log.Printf("** Trying interaction %v", interaction)

	var (
		payload io.Reader
		err     error
	)
	if _, err = os.Stat(interaction.payload); os.IsNotExist(err) {
		// The payload is not a file. Treat it as a string
		payload = strings.NewReader(interaction.payload)
	} else {
		payload, err = os.Open(interaction.payload)
		f, _ := payload.(*os.File)
		defer f.Close()
	}

	body, err := genericRequest(resource, verb, payload)
	c.Check(err, check.IsNil, check.Commentf("Error making the request: %s", err))

	if interaction.responseObject == nil {
		interaction.responseObject = &response{}
	}
	err = json.Unmarshal(body, interaction.responseObject)
	c.Check(err, check.IsNil, check.Commentf("Error unmarshalling the response: %s", err))

	if interaction.responsePattern != "" {
		c.Check(string(body), check.Matches, interaction.responsePattern)
	}
	if interaction.waitPattern != "" {
		err = wait.ForFunction(c, interaction.waitPattern, interaction.waitFunction)
		c.Check(err, check.IsNil, check.Commentf("Error waiting for function: %s", err))
	}
}
Ejemplo n.º 2
0
func (s *loginSuite) TestInvalidCredentialsError(c *check.C) {
	err := s.writeCredentials(invalidLoginName)
	c.Assert(err, check.IsNil, check.Commentf("error writting credentials"))

	expectedMsg := "invalid credentials"
	err = wait.ForFunction(c, expectedMsg, func() (string, error) { return s.stdout.String(), err })
	c.Assert(err, check.IsNil, check.Commentf("didn't get expected invalid credentials error"))

}
Ejemplo n.º 3
0
func init() {
	c := &check.C{}
	// Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293
	// TODO remove once the bug is fixed
	// originally added by elopio - 2015-09-30 to the rollback test, moved
	// here by --fgimenez - 2015-10-15
	wait.ForFunction(c, "regular", partition.Mode)

	cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")
	cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")
}
Ejemplo n.º 4
0
func (s *loginSuite) TestFakeServerIsDetected(c *check.C) {
	s.setUpHTTPServer()
	s.setUpIPTables(c)
	defer s.tearDownIPTables(c)
	defer s.tearDownHTTPServer()

	err := s.writeCredentials(validLoginName)
	c.Assert(err, check.IsNil, check.Commentf("error writting credentials"))

	expectedMsg := fmt.Sprintf("Post https://%s/api/v2/tokens/oauth: x509: certificate is valid for example.com, not %s", loginHost, loginHost)
	err = wait.ForFunction(c, expectedMsg, func() (string, error) { return s.stdout.String(), err })
	c.Assert(err, check.IsNil, check.Commentf("didn't get expected fake server error"))
}