コード例 #1
0
ファイル: snapd_test.go プロジェクト: General-Beck/snappy
// 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))
	}
}
コード例 #2
0
ファイル: login_test.go プロジェクト: dholbach/snappy
func (s *loginSuite) TestInvalidCredentialsError(c *check.C) {
	err := s.writeCredentials(validLoginName)
	c.Assert(err, check.IsNil, check.Commentf("error writting credentials"))

	expectedMsg := "Provided email/password is not correct"
	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: %v", err))
}
コード例 #3
0
ファイル: login_test.go プロジェクト: dholbach/snappy
func (s *loginSuite) TestInvalidLoginError(c *check.C) {
	err := s.writeCredentials(invalidLoginName)
	c.Assert(err, check.IsNil, check.Commentf("error writting credentials"))

	expectedMsg := "Invalid request data"
	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 data error: %v", err))
}
コード例 #4
0
ファイル: base_test.go プロジェクト: robert-ancell/snapd
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")
}
コード例 #5
0
ファイル: login_test.go プロジェクト: robert-ancell/snapd
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"))
}
コード例 #6
0
ファイル: base_test.go プロジェクト: dholbach/snappy
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)

	if _, err := os.Stat(config.DefaultFileName); err == nil {
		cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")
		cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")

		cfg, err := config.ReadConfig(config.DefaultFileName)
		c.Assert(err, check.IsNil, check.Commentf("Error reading config: %v", err))

		setUpSnapd(c, cfg.FromBranch, "")
	}
}
コード例 #7
0
ファイル: snapd_test.go プロジェクト: alecu/snappy
// doInteraction dispatches the given interaction to the resource using the provided verb
func doInteraction(c *check.C, resource, verb string, interaction apiInteraction) {
	log.Printf("** Trying interaction %v", interaction)

	body, err := makeRequest(&requestOptions{resource: resource, verb: verb, payload: interaction.payload})
	c.Assert(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))
	}
}