本文整理汇总了Golang中github.com/tsuru/tsuru/service.ServiceInstance.BindApp方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceInstance.BindApp方法的具体用法?Golang ServiceInstance.BindApp怎么用?Golang ServiceInstance.BindApp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/service.ServiceInstance
的用法示例。
在下文中一共展示了ServiceInstance.BindApp方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBindCallTheServiceAPIAndSetsEnvironmentVariableReturnedFromTheCall
func (s *BindSuite) TestBindCallTheServiceAPIAndSetsEnvironmentVariableReturnedFromTheCall(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.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
}))
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},
}
err = instance.Create()
c.Assert(err, check.IsNil)
defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-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)
app.Provisioner.AddUnits(&a, 1, "web", nil)
err = instance.BindApp(&a, nil)
c.Assert(err, check.IsNil)
newApp, err := app.GetByName(a.Name)
c.Assert(err, check.IsNil)
expectedEnv := map[string]bind.EnvVar{
"DATABASE_USER": {
Name: "DATABASE_USER",
Value: "root",
Public: false,
InstanceName: instance.Name,
},
"DATABASE_PASSWORD": {
Name: "DATABASE_PASSWORD",
Value: "s3cr3t",
Public: false,
InstanceName: instance.Name,
},
}
expectedTsuruServices := map[string][]bind.ServiceInstance{
"mysql": {
bind.ServiceInstance{
Name: instance.Name,
Envs: map[string]string{"DATABASE_USER": "root", "DATABASE_PASSWORD": "s3cr3t"},
},
},
}
servicesEnv := newApp.Env[app.TsuruServicesEnvVar]
var tsuruServices map[string][]bind.ServiceInstance
json.Unmarshal([]byte(servicesEnv.Value), &tsuruServices)
c.Assert(tsuruServices, check.DeepEquals, expectedTsuruServices)
delete(newApp.Env, app.TsuruServicesEnvVar)
c.Assert(newApp.Env, check.DeepEquals, expectedEnv)
}
示例2: TestBindDoesNotFailsAndStopsWhenAppDoesNotHaveAnUnit
func (s *S) TestBindDoesNotFailsAndStopsWhenAppDoesNotHaveAnUnit(c *gocheck.C) {
instance := service.ServiceInstance{Name: "my-mysql", ServiceName: "mysql", Teams: []string{s.team.Name}}
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})
err = instance.BindApp(&a)
c.Assert(err, gocheck.IsNil)
}
示例3: TestBindAppWithNoUnits
func (s *BindSuite) TestBindAppWithNoUnits(c *check.C) {
var called bool
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called = true
w.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
}))
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}}
err = instance.Create()
c.Assert(err, check.IsNil)
defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-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})
err = instance.BindApp(&a, nil)
c.Assert(err, check.IsNil)
err = s.conn.Apps().Find(bson.M{"name": a.Name}).One(&a)
c.Assert(err, check.IsNil)
expectedEnv := map[string]bind.EnvVar{
"DATABASE_USER": {
Name: "DATABASE_USER",
Value: "root",
Public: false,
InstanceName: instance.Name,
},
"DATABASE_PASSWORD": {
Name: "DATABASE_PASSWORD",
Value: "s3cr3t",
Public: false,
InstanceName: instance.Name,
},
}
expectedTsuruServices := map[string][]bind.ServiceInstance{
"mysql": {
bind.ServiceInstance{
Name: instance.Name,
Envs: map[string]string{"DATABASE_USER": "root", "DATABASE_PASSWORD": "s3cr3t"},
},
},
}
servicesEnv := a.Env[app.TsuruServicesEnvVar]
var tsuruServices map[string][]bind.ServiceInstance
json.Unmarshal([]byte(servicesEnv.Value), &tsuruServices)
c.Assert(tsuruServices, check.DeepEquals, expectedTsuruServices)
delete(a.Env, app.TsuruServicesEnvVar)
c.Assert(a.Env, check.DeepEquals, expectedEnv)
}
示例4: TestBindAppFailsWhenEndpointIsDown
func (s *S) TestBindAppFailsWhenEndpointIsDown(c *gocheck.C) {
srvc := service.Service{Name: "mysql", Endpoint: map[string]string{"production": ""}}
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}, []app.Unit{{Ip: "10.10.10.10"}})
c.Assert(err, gocheck.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
err = instance.BindApp(&a)
c.Assert(err, gocheck.NotNil)
}
示例5: TestBindAppFailsWhenEndpointIsDown
func (s *BindSuite) TestBindAppFailsWhenEndpointIsDown(c *check.C) {
srvc := service.Service{Name: "mysql", Endpoint: map[string]string{"production": ""}}
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}}
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, check.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, "web", nil)
err = instance.BindApp(&a, nil)
c.Assert(err, check.NotNil)
}
示例6: TestBindAppMultiUnits
func (s *S) TestBindAppMultiUnits(c *gocheck.C) {
fakeProvisioner := app.Provisioner.(*ttesting.FakeProvisioner)
fakeProvisioner.PrepareOutput([]byte("exported"))
fakeProvisioner.PrepareOutput([]byte("exported"))
var calls int32
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
calls++
}))
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},
}
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.BindApp(&a)
c.Assert(err, gocheck.IsNil)
ok := make(chan bool)
go func() {
t := time.Tick(1)
for _ = <-t; atomic.LoadInt32(&calls) < 2; _ = <-t {
}
ok <- true
}()
select {
case <-ok:
case <-time.After(2e9):
c.Errorf("Did not bind all units afters 2s.")
}
c.Assert(calls, gocheck.Equals, int32(2))
}
示例7: TestBindAddsAppToTheServiceInstance
func (s *S) TestBindAddsAppToTheServiceInstance(c *gocheck.C) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
}))
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}, []app.Unit{{Ip: "10.10.10.10"}})
c.Assert(err, gocheck.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
err = instance.BindApp(&a)
c.Assert(err, gocheck.IsNil)
s.conn.ServiceInstances().Find(bson.M{"name": instance.Name}).One(&instance)
c.Assert(instance.Apps, gocheck.DeepEquals, []string{a.Name})
}
示例8: TestBindCallTheServiceAPIAndSetsEnvironmentVariableReturnedFromTheCall
func (s *S) TestBindCallTheServiceAPIAndSetsEnvironmentVariableReturnedFromTheCall(c *gocheck.C) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
}))
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},
}
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}, []app.Unit{{Ip: "127.0.0.1"}})
c.Assert(err, gocheck.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
err = instance.BindApp(&a)
c.Assert(err, gocheck.IsNil)
newApp, err := app.GetByName(a.Name)
c.Assert(err, gocheck.IsNil)
expectedEnv := map[string]bind.EnvVar{
"DATABASE_USER": {
Name: "DATABASE_USER",
Value: "root",
Public: false,
InstanceName: instance.Name,
},
"DATABASE_PASSWORD": {
Name: "DATABASE_PASSWORD",
Value: "s3cr3t",
Public: false,
InstanceName: instance.Name,
},
}
c.Assert(newApp.Env, gocheck.DeepEquals, expectedEnv)
}
示例9: TestBindAddsAppToTheServiceInstance
func (s *BindSuite) TestBindAddsAppToTheServiceInstance(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.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
}))
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}}
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, check.IsNil)
defer s.conn.Apps().Remove(bson.M{"name": a.Name})
err = instance.BindApp(&a, nil)
c.Assert(err, check.IsNil)
s.conn.ServiceInstances().Find(bson.M{"name": instance.Name}).One(&instance)
c.Assert(instance.Apps, check.DeepEquals, []string{a.Name})
}
示例10: TestBindReturnConflictIfTheAppIsAlreadyBound
func (s *S) TestBindReturnConflictIfTheAppIsAlreadyBound(c *gocheck.C) {
srvc := service.Service{Name: "mysql"}
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})
err = instance.BindApp(&a)
c.Assert(err, gocheck.NotNil)
e, ok := err.(*errors.HTTP)
c.Assert(ok, gocheck.Equals, true)
c.Assert(e.Code, gocheck.Equals, http.StatusConflict)
c.Assert(e, gocheck.ErrorMatches, "^This app is already bound to this service instance.$")
}