本文整理汇总了Golang中github.com/tsuru/tsuru/service.ServiceInstance.UnbindApp方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceInstance.UnbindApp方法的具体用法?Golang ServiceInstance.UnbindApp怎么用?Golang ServiceInstance.UnbindApp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/service.ServiceInstance
的用法示例。
在下文中一共展示了ServiceInstance.UnbindApp方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUnbindRemovesAppFromServiceInstance
func (s *S) TestUnbindRemovesAppFromServiceInstance(c *gocheck.C) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
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})
err = instance.UnbindApp(&a)
c.Assert(err, gocheck.IsNil)
s.conn.ServiceInstances().Find(bson.M{"name": instance.Name}).One(&instance)
c.Assert(instance.Apps, gocheck.DeepEquals, []string{})
}
示例2: TestUnbindRemovesEnvironmentVariableFromApp
func (s *S) TestUnbindRemovesEnvironmentVariableFromApp(c *gocheck.C) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
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"},
}
err = instance.Create()
c.Assert(err, gocheck.IsNil)
defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
a := app.App{
Name: "painkiller",
Teams: []string{s.team.Name},
Env: map[string]bind.EnvVar{
"DATABASE_HOST": {
Name: "DATABASE_HOST",
Value: "arrea",
Public: false,
InstanceName: instance.Name,
},
"MY_VAR": {
Name: "MY_VAR",
Value: "123",
},
},
Units: []app.Unit{
{
Ip: "10.10.10.10",
},
},
}
err = s.conn.Apps().Insert(&a)
c.Assert(err, gocheck.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
err = instance.UnbindApp(&a)
c.Assert(err, gocheck.IsNil)
newApp, err := app.GetByName(a.Name)
c.Assert(err, gocheck.IsNil)
expected := map[string]bind.EnvVar{
"MY_VAR": {
Name: "MY_VAR",
Value: "123",
},
}
c.Assert(newApp.Env, gocheck.DeepEquals, expected)
}
示例3: TestUnbindCallsTheUnbindMethodFromAPI
func (s *BindSuite) TestUnbindCallsTheUnbindMethodFromAPI(c *check.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/bind" {
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, check.IsNil)
defer s.conn.Services().Remove(bson.M{"_id": "mysql"})
a, err := createTestApp(s.conn, "painkiller", "", []string{s.team.Name})
c.Assert(err, check.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
app.Provisioner.Provision(&a)
defer app.Provisioner.Destroy(&a)
units, _ := app.Provisioner.AddUnits(&a, 1, "web", nil)
instance := service.ServiceInstance{
Name: "my-mysql",
ServiceName: "mysql",
Teams: []string{s.team.Name},
Apps: []string{"painkiller"},
Units: []string{units[0].ID},
}
err = instance.Create()
c.Assert(err, check.IsNil)
defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
err = instance.UnbindApp(&a, nil)
c.Assert(err, check.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.")
}
}
示例4: TestUnbindMultiUnits
func (s *BindSuite) TestUnbindMultiUnits(c *check.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, check.IsNil)
defer s.conn.Services().Remove(bson.M{"_id": "mysql"})
a, err := createTestApp(s.conn, "painkiller", "", []string{s.team.Name})
c.Assert(err, check.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
app.Provisioner.Provision(&a)
defer app.Provisioner.Destroy(&a)
units, _ := app.Provisioner.AddUnits(&a, 2, "web", nil)
instance := service.ServiceInstance{
Name: "my-mysql",
ServiceName: "mysql",
Teams: []string{s.team.Name},
Apps: []string{"painkiller"},
Units: []string{units[0].ID, units[1].ID},
}
instance.Create()
defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
err = instance.UnbindApp(&a, nil)
c.Assert(err, check.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(time.Second):
c.Error("endpoint not called")
}
}
示例5: TestUnbindReturnsPreconditionFailedIfTheAppIsNotBoundToTheInstance
func (s *S) TestUnbindReturnsPreconditionFailedIfTheAppIsNotBoundToTheInstance(c *gocheck.C) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
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}}
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})
err = instance.UnbindApp(&a)
c.Assert(err, gocheck.NotNil)
e, ok := err.(*errors.HTTP)
c.Assert(ok, gocheck.Equals, true)
c.Assert(e, gocheck.ErrorMatches, "^This app is not bound to this service instance.$")
}
示例6: TestUnbindRemovesEnvironmentVariableFromApp
func (s *BindSuite) TestUnbindRemovesEnvironmentVariableFromApp(c *check.C) {
fakeProvisioner := app.Provisioner.(*provisiontest.FakeProvisioner)
fakeProvisioner.PrepareOutput([]byte("exported"))
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
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, check.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, check.IsNil)
defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
a := app.App{
Name: "painkiller",
Teams: []string{s.team.Name},
Env: map[string]bind.EnvVar{
"DATABASE_HOST": {
Name: "DATABASE_HOST",
Value: "arrea",
Public: false,
InstanceName: instance.Name,
},
"MY_VAR": {
Name: "MY_VAR",
Value: "123",
},
app.TsuruServicesEnvVar: {
Name: app.TsuruServicesEnvVar,
Value: `{"mysql": [{"instance_name": "my-mysql", "envs": {"DATABASE_USER": "root", "DATABASE_PASSWORD": "s3cre3t"}},
{"instance_name": "other-mysql", "envs": {"DATABASE_USER": "1", "DATABASE_PASSWORD": "2"}}]}`,
},
},
}
err = s.conn.Apps().Insert(&a)
c.Assert(err, check.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
err = app.Provisioner.Provision(&a)
c.Assert(err, check.IsNil)
defer app.Provisioner.Destroy(&a)
err = instance.UnbindApp(&a, nil)
c.Assert(err, check.IsNil)
newApp, err := app.GetByName(a.Name)
c.Assert(err, check.IsNil)
services := newApp.Env[app.TsuruServicesEnvVar].Value
var tsuruServices map[string][]bind.ServiceInstance
err = json.Unmarshal([]byte(services), &tsuruServices)
c.Assert(err, check.IsNil)
c.Assert(tsuruServices, check.DeepEquals, map[string][]bind.ServiceInstance{
"mysql": {
{
Name: "other-mysql",
Envs: map[string]string{"DATABASE_USER": "1", "DATABASE_PASSWORD": "2"},
},
},
})
delete(newApp.Env, app.TsuruServicesEnvVar)
expected := map[string]bind.EnvVar{
"MY_VAR": {
Name: "MY_VAR",
Value: "123",
},
}
c.Assert(newApp.Env, check.DeepEquals, expected)
}