Beispiel #1
0
func (s *S) TestGetAWSAuth(c *gocheck.C) {
	access, err := config.Get("aws:access-key-id")
	c.Assert(err, gocheck.IsNil)
	secret, err := config.Get("aws:secret-access-key")
	c.Assert(err, gocheck.IsNil)
	auth := getAWSAuth()
	c.Assert(auth.AccessKey, gocheck.Equals, access)
	c.Assert(auth.SecretKey, gocheck.Equals, secret)
}
func (s *S) TestConnectDefaultSettings(c *gocheck.C) {
	oldURL, _ := config.Get("database:url")
	defer config.Set("database:url", oldURL)
	oldName, _ := config.Get("database:name")
	defer config.Set("database:name", oldName)
	config.Unset("database:url")
	config.Unset("database:name")
	Connect()
	c.Assert(Session.DB.Name, gocheck.Equals, "gandalf")
	c.Assert(Session.DB.Session.LiveServers(), gocheck.DeepEquals, []string{"localhost:27017"})
}
Beispiel #3
0
func (s *S) TestDeleteConnectionError(c *C) {
	old, _ := config.Get("queue-server")
	defer config.Set("queue-server", old)
	config.Unset("queue-server")
	err := Delete(nil)
	c.Assert(err, NotNil)
}
Beispiel #4
0
func (s *S) TestLoadConfigSetsTheTokenExpireToTheValueInTheConfig(c *C) {
	configuredToken, err := config.Get("auth:token-expire-days")
	c.Assert(err, IsNil)
	expected := time.Duration(int64(configuredToken.(int)) * 24 * int64(time.Hour))
	loadConfig()
	c.Assert(tokenExpire, Equals, expected)
}
Beispiel #5
0
func getPort() (string, error) {
	port, err := config.Get("docker:run-cmd:port")
	if err != nil {
		return "", err
	}
	return fmt.Sprint(port), nil
}
Beispiel #6
0
func (s *S) TestAddBackendWithVpc(c *gocheck.C) {
	old, _ := config.Get("juju:elb-avail-zones")
	config.Unset("juju:elb-avail-zones")
	config.Set("juju:elb-use-vpc", true)
	config.Set("juju:elb-vpc-subnets", []string{"subnet-a4a3a2a1", "subnet-002200"})
	config.Set("juju:elb-vpc-secgroups", []string{"sg-0900"})
	defer func() {
		config.Set("juju:elb-avail-zones", old)
		config.Unset("juju:elb-use-vpc")
		config.Unset("juju:elb-vpc-subnets")
		config.Unset("juju:elb-vpc-secgroups")
	}()
	router := elbRouter{}
	err := router.AddBackend("tip")
	c.Assert(err, gocheck.IsNil)
	defer router.RemoveBackend("tip")
	resp, err := s.client.DescribeLoadBalancers("tip")
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1)
	lbd := resp.LoadBalancerDescriptions[0]
	c.Assert(lbd.Subnets, gocheck.DeepEquals, []string{"subnet-a4a3a2a1", "subnet-002200"})
	c.Assert(lbd.SecurityGroups, gocheck.DeepEquals, []string{"sg-0900"})
	c.Assert(lbd.Scheme, gocheck.Equals, "internal")
	c.Assert(lbd.AvailZones, gocheck.HasLen, 0)
}
Beispiel #7
0
func (s *S) TestLoadConfigTokenExpire(c *gocheck.C) {
	configuredToken, err := config.Get("auth:token-expire-days")
	c.Assert(err, gocheck.IsNil)
	expected := time.Duration(int64(configuredToken.(int)) * 24 * int64(time.Hour))
	loadConfig()
	c.Assert(tokenExpire, gocheck.Equals, expected)
}
Beispiel #8
0
func (s *ELBSuite) TestCreateELBUsingVPC(c *gocheck.C) {
	old, _ := config.Get("juju:elb-avail-zones")
	config.Unset("juju:elb-avail-zones")
	config.Set("juju:elb-use-vpc", true)
	config.Set("juju:elb-vpc-subnets", []string{"subnet-a4a3a2a1", "subnet-002200"})
	config.Set("juju:elb-vpc-secgroups", []string{"sg-0900"})
	defer func() {
		config.Set("juju:elb-avail-zones", old)
		config.Unset("juju:elb-use-vpc")
		config.Unset("juju:elb-vpc-subnets")
		config.Unset("juju:elb-vpc-secgroups")
	}()
	app := testing.NewFakeApp("relax", "who", 1)
	manager := ELBManager{}
	err := manager.Create(app)
	c.Assert(err, gocheck.IsNil)
	defer s.client.DeleteLoadBalancer(app.GetName())
	conn, coll := manager.collection()
	defer conn.Close()
	defer coll.Remove(bson.M{"name": app.GetName()})
	resp, err := s.client.DescribeLoadBalancers(app.GetName())
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1)
	lbd := resp.LoadBalancerDescriptions[0]
	c.Assert(lbd.Subnets, gocheck.DeepEquals, []string{"subnet-a4a3a2a1", "subnet-002200"})
	c.Assert(lbd.SecurityGroups, gocheck.DeepEquals, []string{"sg-0900"})
	c.Assert(lbd.Scheme, gocheck.Equals, "internal")
	c.Assert(lbd.AvailZones, gocheck.HasLen, 0)
}
Beispiel #9
0
func (c *container) getAddress() string {
	hostAddr, err := config.Get("docker:host-address")
	if err != nil {
		log.Printf("Failed to obtain container address: %s", err.Error())
		return ""
	}
	return fmt.Sprintf("http://%s:%s", hostAddr, c.HostPort)
}
Beispiel #10
0
func (s *S) TestGetGitServerPanicsIfTheConfigFileHasNoServer(c *gocheck.C) {
	oldConfig, err := config.Get("git")
	c.Assert(err, gocheck.IsNil)
	err = config.Unset("git")
	c.Assert(err, gocheck.IsNil)
	defer config.Set("git", oldConfig)
	c.Assert(getGitServer, gocheck.PanicMatches, `key "git:host" not found`)
}
Beispiel #11
0
func syncFile(name string, server string) string {
	files, _ := config.Get("files")
	mfiles := files.(map[interface{}]interface{})
	file := mfiles[name].(map[interface{}]interface{})
	fileSync := FileSync{local: file["local"].(string), dest: file["dest"].(string), post_cmd: file["post_cmd"].(string), group: file["group"].(string)}
	executeScp(nil, server, fileSync.local, fileSync.dest)
	return "SCP: " + fileSync.local + " on " + server + "\n"
}
Beispiel #12
0
func (s *S) TestContainerCreateWithoutHostAddr(c *gocheck.C) {
	old, _ := config.Get("docker:host-address")
	defer config.Set("docker:host-address", old)
	config.Unset("docker:host-address")
	container := container{AppName: "myapp", Type: "python"}
	err := container.create(testing.NewFakeApp("myapp", "python", 1))
	c.Assert(err, gocheck.NotNil)
}
Beispiel #13
0
func (s *S) TestPutConnectionFailure(c *C) {
	old, _ := config.Get("queue-server")
	defer config.Set("queue-server", old)
	config.Unset("queue-server")
	msg := Message{Action: "regenerate-apprc"}
	err := Put(&msg)
	c.Assert(err, NotNil)
}
Beispiel #14
0
func (s *S) TestGetServerUri(c *gocheck.C) {
	server, err := config.GetString("git:host")
	c.Assert(err, gocheck.IsNil)
	protocol, err := config.GetString("git:protocol")
	port, err := config.Get("git:port")
	uri := GitServerUri()
	c.Assert(uri, gocheck.Equals, fmt.Sprintf("%s://%s:%d", protocol, server, port))
}
Beispiel #15
0
func (s *S) TestGetConnectionError(c *C) {
	old, _ := config.Get("queue-server")
	defer config.Set("queue-server", old)
	config.Unset("queue-server")
	msg, err := Get(1e6)
	c.Assert(msg, IsNil)
	c.Assert(err, NotNil)
}
Beispiel #16
0
func (s *S) TestSendEmailUndefinedUser(c *gocheck.C) {
	old, _ := config.Get("smtp:user")
	defer config.Set("smtp:user", old)
	config.Unset("smtp:user")
	err := sendEmail("*****@*****.**", []byte("Hello world!"))
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `Setting "smtp:user" is not defined`)
}
Beispiel #17
0
func (s *S) TestPullRepositoryUndefinedPath(c *gocheck.C) {
	old, _ := config.Get("git:unit-repo")
	config.Unset("git:unit-repo")
	defer config.Set("git:unit-repo", old)
	_, err := pull(nil, nil)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `Tsuru is misconfigured: key "git:unit-repo" not found`)
}
Beispiel #18
0
func (s *S) TestContainerSSHWithoutUserConfigured(c *gocheck.C) {
	old, _ := config.Get("docker:ssh:user")
	defer config.Set("docker:ssh:user", old)
	config.Unset("docker:ssh:user")
	container := container{ID: "c-01", IP: "127.0.0.1"}
	err := container.ssh(nil, nil, "ls", "-a")
	c.Assert(err, gocheck.NotNil)
}
Beispiel #19
0
func (s *S) TestGetSSHCommandsMissingAddKeyCommand(c *gocheck.C) {
	old, _ := config.Get("docker:ssh:add-key-cmd")
	defer config.Set("docker:ssh:add-key-cmd", old)
	config.Unset("docker:ssh:add-key-cmd")
	commands, err := sshCmds()
	c.Assert(commands, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
}
Beispiel #20
0
func (s *BeanstalkSuite) TestConnectionResfused(c *gocheck.C) {
	old, _ := config.Get("queue-server")
	config.Set("queue-server", "127.0.0.1:11301")
	defer config.Set("queue-server", old)
	conn, err := connection()
	c.Assert(conn, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
}
Beispiel #21
0
func (s *S) TestGetPortUndefined(c *gocheck.C) {
	old, _ := config.Get("docker:run-cmd:port")
	defer config.Set("docker:run-cmd:port", old)
	config.Unset("docker:run-cmd:port")
	port, err := getPort()
	c.Assert(port, gocheck.Equals, "")
	c.Assert(err, gocheck.NotNil)
}
Beispiel #22
0
func (s *S) TestGetGitServerPanicsIfTheConfigFileHasNoServer(c *C) {
	oldConfig, err := config.Get("git")
	c.Assert(err, IsNil)
	err = config.Unset("git")
	c.Assert(err, IsNil)
	defer config.Set("git", oldConfig)
	c.Assert(getGitServer, PanicMatches, "key git:host not found")
}
Beispiel #23
0
func (s *BeanstalkSuite) TestConnectionQueueServerUndefined(c *gocheck.C) {
	old, _ := config.Get("queue-server")
	config.Unset("queue-server")
	defer config.Set("queue-server", old)
	conn, err := connection()
	c.Assert(err, gocheck.IsNil)
	c.Assert(conn, gocheck.NotNil)
}
Beispiel #24
0
func (s *S) TestGetPortInteger(c *gocheck.C) {
	old, _ := config.Get("docker:run-cmd:port")
	defer config.Set("docker:run-cmd:port", old)
	config.Set("docker:run-cmd:port", 8888)
	port, err := getPort()
	c.Assert(err, gocheck.IsNil)
	c.Assert(port, gocheck.Equals, "8888")
}
Beispiel #25
0
// TODO(fss): simplify this test. Right now, it's a little monster.
func (s *S) TestCreateApp(c *C) {
	patchRandomReader()
	defer unpatchRandomReader()
	h := testHandler{}
	ts := s.t.StartGandalfTestServer(&h)
	defer ts.Close()
	server := testing.FakeQueueServer{}
	server.Start("127.0.0.1:0")
	defer server.Stop()
	a := App{
		Name:      "appname",
		Framework: "django",
		Units:     []Unit{{Machine: 3}},
	}
	expectedHost := "localhost"
	config.Set("host", expectedHost)
	old, err := config.Get("queue-server")
	if err != nil {
		defer config.Set("queue-server", old)
	}
	config.Set("queue-server", server.Addr())

	err = CreateApp(&a, 3)
	c.Assert(err, IsNil)
	defer a.Destroy()
	c.Assert(a.State, Equals, "pending")
	var retrievedApp App
	err = db.Session.Apps().Find(bson.M{"name": a.Name}).One(&retrievedApp)
	c.Assert(err, IsNil)
	c.Assert(retrievedApp.Name, Equals, a.Name)
	c.Assert(retrievedApp.Framework, Equals, a.Framework)
	c.Assert(retrievedApp.State, Equals, a.State)
	env := a.InstanceEnv(s3InstanceName)
	c.Assert(env["TSURU_S3_ENDPOINT"].Value, Equals, s.t.S3Server.URL())
	c.Assert(env["TSURU_S3_ENDPOINT"].Public, Equals, false)
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Value, Equals, "true")
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Public, Equals, false)
	e, ok := env["TSURU_S3_ACCESS_KEY_ID"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	e, ok = env["TSURU_S3_SECRET_KEY"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	c.Assert(env["TSURU_S3_BUCKET"].Value, HasLen, maxBucketSize)
	c.Assert(env["TSURU_S3_BUCKET"].Value, Equals, "appnamee3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3")
	c.Assert(env["TSURU_S3_BUCKET"].Public, Equals, false)
	env = a.InstanceEnv("")
	c.Assert(env["APPNAME"].Value, Equals, a.Name)
	c.Assert(env["APPNAME"].Public, Equals, false)
	c.Assert(env["TSURU_HOST"].Value, Equals, expectedHost)
	c.Assert(env["TSURU_HOST"].Public, Equals, false)
	expectedMessage := queue.Message{
		Action: RegenerateApprc,
		Args:   []string{a.Name},
	}
	c.Assert(server.Messages(), DeepEquals, []queue.Message{expectedMessage})
	c.Assert(s.provisioner.GetUnits(&a), HasLen, 3)
}
Beispiel #26
0
func (s *S) TestDockerDeployNoDeployCommand(c *gocheck.C) {
	old, _ := config.Get("docker:deploy-cmd")
	defer config.Set("docker:deploy-cmd", old)
	config.Unset("docker:deploy-cmd")
	var container container
	err := container.deploy(nil)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `key "docker:deploy-cmd" not found`)
}
Beispiel #27
0
func (s *S) TestDockerDeployNoBinaryToRun(c *gocheck.C) {
	old, _ := config.Get("docker:run-cmd:bin")
	defer config.Set("docker:run-cmd:bin", old)
	config.Unset("docker:run-cmd:bin")
	var container container
	err := container.deploy(nil)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `key "docker:run-cmd:bin" not found`)
}
Beispiel #28
0
func (s *S) TestContainerInspectNoBinary(c *gocheck.C) {
	old, _ := config.Get("docker:binary")
	defer config.Set("docker:binary", old)
	config.Unset("docker:binary")
	container := container{Id: "something"}
	got, err := container.inspect()
	c.Assert(got, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
}
Beispiel #29
0
func (s *S) TestCloneRepositoryUndefinedPath(c *gocheck.C) {
	old, _ := config.Get("git:unit-repo")
	config.Unset("git:unit-repo")
	defer config.Set("git:unit-repo", old)
	u := FakeUnit{name: "my-unit"}
	_, err := clone(&u)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `Tsuru is misconfigured: key "git:unit-repo" not found`)
}
Beispiel #30
0
func (s *S) TestLoadConfigCostUndefined(c *gocheck.C) {
	key := "auth:hash-cost"
	oldConfig, err := config.Get(key)
	c.Assert(err, gocheck.IsNil)
	config.Unset(key)
	defer config.Set(key, oldConfig)
	err = loadConfig()
	c.Assert(err, gocheck.NotNil)
}