예제 #1
0
// Tests for Keys API
func (s *CloudAPISuite) TestListKeys(c *gc.C) {
	k := s.createKey(c, testKeyName, testKey)
	defer s.deleteKey(c, testKeyName)

	keys, err := s.service.ListKeys()
	c.Assert(err, gc.IsNil)
	for _, key := range keys {
		if c.Check(&key, gc.DeepEquals, k) {
			c.SucceedNow()
		}
	}
	c.Fatalf("Obtained keys [%s] do not contain test key [%s]", keys, k)
}
예제 #2
0
// Test for Machine API
func (s *CloudAPISuite) TestListMachines(c *gc.C) {
	m := s.createMachine(c, testMachineName, testPackage, testImage, nil, nil)
	defer s.deleteMachine(c, m.Id)

	machines, err := s.service.ListMachines(nil)
	c.Assert(err, gc.IsNil)
	for _, machine := range machines {
		if machine.Id == m.Id {
			c.SucceedNow()
		}
	}
	c.Fatalf("Obtained machine [%v] do not contain test machine [%v]", machines, m)
}
예제 #3
0
func (s *FoundationS) TestSucceedNow(c *gocheck.C) {
	defer (func() {
		if c.Failed() {
			c.Error("SucceedNow() didn't succeed the test")
		}
		if c.GetTestLog() != "" {
			c.Error("Something got logged:\n" + c.GetTestLog())
		}
	})()

	c.Fail()
	c.SucceedNow()
	c.Log("SucceedNow() didn't stop the test")
}
예제 #4
0
파일: publish_test.go 프로젝트: jkary/core
func (s *PublishSuite) TestInferURL(c *gc.C) {
	addMeta(c, s.branch, "")

	cmd := &PublishCommand{}
	cmd.ChangePushLocation(func(location string) string {
		c.Assert(location, gc.Equals, "lp:charms/precise/wordpress")
		c.SucceedNow()
		panic("unreachable")
	})

	_, err := testing.RunCommandInDir(c, envcmd.Wrap(cmd), []string{"precise/wordpress"}, s.dir)
	c.Assert(err, gc.IsNil)
	c.Fatal("shouldn't get here; location closure didn't run?")
}
예제 #5
0
func (s *LiveTests) TestListKeys(c *gc.C) {
	s.createKey(c)

	keys, err := s.testClient.ListKeys()
	c.Assert(err, gc.IsNil)
	c.Assert(keys, gc.NotNil)
	fakeKey := cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey}
	for _, k := range keys {
		if c.Check(k, gc.DeepEquals, fakeKey) {
			c.SucceedNow()
		}
	}
	c.Fatalf("Obtained keys [%s] do not contain test key [%s]", keys, fakeKey)
}
예제 #6
0
// Tests for Machines API
func (s *CloudAPIHTTPSuite) TestListMachines(c *gc.C) {
	var expected []cloudapi.Machine
	m := s.createMachine(c, testMachineName, testPackage, testImage, nil, nil)
	defer s.deleteMachine(c, m.Id)

	resp, err := s.sendRequest("GET", path.Join(testUserAccount, "machines"), nil, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(resp.StatusCode, gc.Equals, http.StatusOK)
	assertJSON(c, resp, &expected)
	for _, machine := range expected {
		if machine.Id == m.Id {
			c.SucceedNow()
		}
	}
	c.Fatalf("Obtained machine [%s] do not contain test machine [%s]", expected, m)
}
예제 #7
0
// Tests for Keys API
func (s *CloudAPIHTTPSuite) TestListKeys(c *gc.C) {
	var expected []cloudapi.Key
	k := s.createKey(c, testKeyName, testKey)
	defer s.deleteKey(c, testKeyName)

	resp, err := s.sendRequest("GET", path.Join(testUserAccount, "keys"), nil, nil)
	c.Assert(err, gc.IsNil)
	c.Assert(resp.StatusCode, gc.Equals, http.StatusOK)
	assertJSON(c, resp, &expected)
	for _, key := range expected {
		if c.Check(&key, gc.DeepEquals, k) {
			c.SucceedNow()
		}
	}
	c.Fatalf("Obtained keys [%s] do not contain test key [%s]", expected, k)
}
예제 #8
0
파일: bind_test.go 프로젝트: ningjh/tsuru
func (s *S) TestUnbindMultiUnits(c *gocheck.C) {
	var calls int32
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		i := atomic.LoadInt32(&calls)
		i++
		atomic.StoreInt32(&calls, i)
		w.WriteHeader(http.StatusNoContent)
	}))
	defer ts.Close()
	srvc := service.Service{Name: "mysql", Endpoint: map[string]string{"production": ts.URL}}
	err := srvc.Create()
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Services().Remove(bson.M{"_id": "mysql"})
	instance := service.ServiceInstance{
		Name:        "my-mysql",
		ServiceName: "mysql",
		Teams:       []string{s.team.Name},
		Apps:        []string{"painkiller"},
	}
	instance.Create()
	defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
	a, err := createTestApp(s.conn, "painkiller", "", []string{s.team.Name})
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Apps().Remove(bson.M{"name": a.Name})
	app.Provisioner.Provision(&a)
	defer app.Provisioner.Destroy(&a)
	app.Provisioner.AddUnits(&a, 1)
	err = instance.UnbindApp(&a)
	c.Assert(err, gocheck.IsNil)
	ok := make(chan bool, 1)
	go func() {
		t := time.Tick(1)
		for _ = <-t; atomic.LoadInt32(&calls) < 2; _ = <-t {
		}
		ok <- true
	}()
	select {
	case <-ok:
		c.SucceedNow()
	case <-time.After(1 * time.Second):
		c.Error("endpoint not called")
	}
}
예제 #9
0
func (s *BindSuite) TestUnbindCallsTheUnbindMethodFromAPI(c *gocheck.C) {
	var called int32
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "DELETE" && r.URL.Path == "/resources/my-mysql/hostname/10.10.10.1" {
			atomic.StoreInt32(&called, 1)
		}
	}))
	defer ts.Close()
	srvc := service.Service{Name: "mysql", Endpoint: map[string]string{"production": ts.URL}}
	err := srvc.Create()
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Services().Remove(bson.M{"_id": "mysql"})
	instance := service.ServiceInstance{
		Name:        "my-mysql",
		ServiceName: "mysql",
		Teams:       []string{s.team.Name},
		Apps:        []string{"painkiller"},
	}
	err = instance.Create()
	c.Assert(err, gocheck.IsNil)
	defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
	a, err := createTestApp(s.conn, "painkiller", "", []string{s.team.Name})
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Apps().Remove(bson.M{"name": a.Name})
	app.Provisioner.Provision(&a)
	defer app.Provisioner.Destroy(&a)
	app.Provisioner.AddUnits(&a, 1)
	err = instance.UnbindApp(&a)
	c.Assert(err, gocheck.IsNil)
	ch := make(chan bool)
	go func() {
		t := time.Tick(1)
		for _ = <-t; atomic.LoadInt32(&called) == 0; _ = <-t {
		}
		ch <- true
	}()
	select {
	case <-ch:
		c.SucceedNow()
	case <-time.After(1e9):
		c.Errorf("Failed to call API after 1 second.")
	}
}