forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert integration tests to use ginkgo
Signed-off-by: Maria Shaldibina <[email protected]>
- Loading branch information
1 parent
d274463
commit 78d492c
Showing
11 changed files
with
232 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
GOPATH=/home/vagrant/go | ||
export GOROOT=/usr/local/go | ||
export PATH=$GOROOT/bin:$PATH | ||
|
||
echo "Installing bosh-agent..." | ||
mkdir -p $(dirname $GOROOT) | ||
chmod -R a+w $GOROOT | ||
|
||
if [ ! -d $TMPDIR ]; then | ||
mkdir -p $TMPDIR | ||
fi | ||
|
||
agent_dir=$GOPATH/src/github.com/cloudfoundry/bosh-agent | ||
|
||
pushd $agent_dir | ||
sudo sv stop agent | ||
|
||
# build agent | ||
bin/build | ||
|
||
# install new agent | ||
sudo cp out/bosh-agent /var/vcap/bosh/bin/bosh-agent | ||
|
||
# start agent | ||
sudo sv start agent | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package integration_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
boshlog "github.com/cloudfoundry/bosh-agent/logger" | ||
boshsys "github.com/cloudfoundry/bosh-agent/system" | ||
|
||
. "github.com/cloudfoundry/bosh-agent/integration" | ||
) | ||
|
||
var _ = Describe("ConfigDrive", func() { | ||
var ( | ||
testEnvironment TestEnvironment | ||
) | ||
|
||
BeforeEach(func() { | ||
logger := boshlog.NewLogger(boshlog.LevelDebug) | ||
cmdRunner := boshsys.NewExecCmdRunner(logger) | ||
testEnvironment = NewTestEnvironment(cmdRunner) | ||
}) | ||
|
||
Context("when infrastructure is openstack", func() { | ||
BeforeEach(func() { | ||
err := testEnvironment.SetInfrastructure("openstack") | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
Context("when vm is using config drive", func() { | ||
BeforeEach(func() { | ||
err := testEnvironment.SetupConfigDrive() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = testEnvironment.RemoveAgentSettings() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = testEnvironment.StartRegistry(`"{\"agent_id\":\"fake-agent-id\"}"`) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = testEnvironment.UpdateAgentConfig("config-drive-agent.json") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = testEnvironment.RestartAgent() | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("using config drive to get registry URL", func() { | ||
settingsJSON, err := testEnvironment.GetFileContents("/var/vcap/bosh/settings.json") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(settingsJSON).To(ContainSubstring("fake-agent-id")) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package integration_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestIntegration(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Integration Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
|
||
boshsys "github.com/cloudfoundry/bosh-agent/system" | ||
) | ||
|
||
type TestEnvironment struct { | ||
cmdRunner boshsys.CmdRunner | ||
} | ||
|
||
func NewTestEnvironment( | ||
cmdRunner boshsys.CmdRunner, | ||
) TestEnvironment { | ||
return TestEnvironment{ | ||
cmdRunner: cmdRunner, | ||
} | ||
} | ||
|
||
func (t TestEnvironment) SetInfrastructure(name string) error { | ||
_, err := t.RunCommand(fmt.Sprintf("echo '%s' | sudo tee /var/vcap/bosh/etc/infrastructure", name)) | ||
return err | ||
} | ||
|
||
func (t TestEnvironment) SetupConfigDrive() error { | ||
setupConfigDriveTemplate := ` | ||
export GOPATH=/home/vagrant/go | ||
export GOROOT=/usr/local/go | ||
export PATH=$GOROOT/bin:$PATH | ||
sudo dd if=/dev/zero of=/virtualfs bs=1024 count=1024 | ||
sudo losetup /dev/loop2 /virtualfs | ||
sudo mkfs -t ext3 -m 1 -v /dev/loop2 | ||
sudo e2label /dev/loop2 config-2 | ||
sudo mkdir /tmp/config-drive | ||
sudo mount /dev/disk/by-label/config-2 /tmp/config-drive | ||
sudo chown vagrant:vagrant /tmp/config-drive | ||
sudo mkdir -p /tmp/config-drive/ec2/latest | ||
sudo cp %s/meta-data.json /tmp/config-drive/ec2/latest/meta-data.json | ||
sudo cp %s/user-data /tmp/config-drive/ec2/latest | ||
sudo umount /tmp/config-drive | ||
` | ||
setupConfigDriveScript := fmt.Sprintf(setupConfigDriveTemplate, t.assetsDir(), t.assetsDir()) | ||
|
||
_, err := t.RunCommand(setupConfigDriveScript) | ||
return err | ||
} | ||
|
||
func (t TestEnvironment) RemoveAgentSettings() error { | ||
_, err := t.RunCommand("sudo rm -f /var/vcap/bosh/settings.json") | ||
return err | ||
} | ||
|
||
func (t TestEnvironment) UpdateAgentConfig(configFile string) error { | ||
_, err := t.RunCommand( | ||
fmt.Sprintf( | ||
"sudo cp %s/%s /var/vcap/bosh/agent.json", | ||
t.assetsDir(), | ||
configFile, | ||
), | ||
) | ||
return err | ||
} | ||
|
||
func (t TestEnvironment) RestartAgent() error { | ||
_, err := t.RunCommand("sudo sv stop agent && sudo sv start agent") | ||
return err | ||
} | ||
|
||
func (t TestEnvironment) StartRegistry(settings string) error { | ||
|
||
_, err := t.RunCommand( | ||
fmt.Sprintf( | ||
`nohup %s/tmp/fake-registry -user user -password pass -host localhost -port 9090 -instance instance-id -settings "%s" &> /dev/null &`, | ||
t.agentDir(), | ||
settings, | ||
), | ||
) | ||
return err | ||
} | ||
|
||
func (t TestEnvironment) GetFileContents(filePath string) (string, error) { | ||
return t.RunCommand( | ||
fmt.Sprintf( | ||
`cat %s`, | ||
filePath, | ||
), | ||
) | ||
} | ||
|
||
func (t TestEnvironment) RunCommand(command string) (string, error) { | ||
stdout, _, _, err := t.cmdRunner.RunCommand( | ||
"vagrant", | ||
"ssh", | ||
"-c", | ||
command, | ||
) | ||
|
||
return stdout, err | ||
} | ||
|
||
func (t TestEnvironment) agentDir() string { | ||
return "/home/vagrant/go/src/github.com/cloudfoundry/bosh-agent" | ||
} | ||
|
||
func (t TestEnvironment) assetsDir() string { | ||
return fmt.Sprintf("%s/integration/assets", t.agentDir()) | ||
} |