-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from bravetools/testing
Testing
- Loading branch information
Showing
4 changed files
with
202 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Use `macpine` to spin up bravetools testing environment on Mac | ||
|
||
```bash | ||
alpine launch --image alpine_3.16.0_lxd --name bravetools --mount $PWD | ||
alpine exec bravetools "ash /root/mnt/macpine/bootstrap.sh" | ||
``` | ||
|
||
## Unit Testing | ||
|
||
Run Unit tests directly on the VM | ||
|
||
```bash | ||
alpine ssh bravetools | ||
cd mnt | ||
go test -v ./... | ||
``` |
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,21 @@ | ||
set -e | ||
|
||
cat > /etc/apk/repositories << EOF; $(echo) | ||
https://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main/ | ||
https://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community/ | ||
https://dl-cdn.alpinelinux.org/alpine/edge/testing/ | ||
EOF | ||
apk add --update --no-cache go make musl-dev curl linux-headers sudo | ||
|
||
export GOPATH=/root/go | ||
export PATH=${GOPATH}/bin:/usr/local/go/bin:$PATH | ||
export GOBIN=$GOROOT/bin | ||
mkdir -p ${GOPATH}/src ${GOPATH}/bin | ||
export GO111MODULE=on | ||
|
||
go version | ||
|
||
cd /mnt ; make linux; cd ../ | ||
brave init |
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,164 @@ | ||
package platform | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bravetools/bravetools/shared" | ||
) | ||
|
||
func Test_DeleteLocalImage(t *testing.T) { | ||
host := *NewBraveHost() | ||
|
||
bravefile, err := shared.GetBravefileFromLXD("alpine/edge/amd64") | ||
if err != nil { | ||
t.Error("shared.GetBravefileFromLXD: ", err) | ||
} | ||
|
||
err = host.BuildImage(bravefile) | ||
if err != nil { | ||
t.Error("host.BuildImage: ", err) | ||
} | ||
|
||
err = host.DeleteLocalImage("brave-base-alpine-edge-1.0") | ||
if err != nil { | ||
t.Error("host.DeleteImageByName: ", err) | ||
} | ||
|
||
} | ||
|
||
func Test_HostInfo(t *testing.T) { | ||
host := *NewBraveHost() | ||
backend := NewLxd(host.Settings) | ||
|
||
err := host.HostInfo(backend, false) | ||
if err != nil { | ||
t.Error("host.HostInfo: ", err) | ||
} | ||
} | ||
|
||
func Test_BuildImage(t *testing.T) { | ||
host := *NewBraveHost() | ||
|
||
bravefile := *shared.NewBravefile() | ||
bravefile.Base.Image = "alpine/edge/amd64" | ||
bravefile.Base.Location = "public" | ||
|
||
bravefile.SystemPackages.Manager = "apk" | ||
bravefile.SystemPackages.System = []string{"htop", "make"} | ||
|
||
runCommand := &shared.RunCommand{} | ||
runCommand.Command = "echo" | ||
runCommand.Args = []string{"Hello World"} | ||
|
||
bravefile.Run = []shared.RunCommand{*runCommand} | ||
|
||
bravefile.PlatformService.Name = "alpine-test" | ||
bravefile.PlatformService.Version = "1.0" | ||
|
||
err := host.BuildImage(&bravefile) | ||
if err != nil { | ||
t.Error("host.BuildImage: ", err) | ||
} | ||
|
||
err = host.DeleteLocalImage("alpine-test-1.0") | ||
if err != nil { | ||
t.Error("host.DeleteImageByName: ", err) | ||
} | ||
} | ||
|
||
func Test_InitUnit(t *testing.T) { | ||
host := *NewBraveHost() | ||
backend := NewLxd(host.Settings) | ||
|
||
bravefile := *shared.NewBravefile() | ||
bravefile.Base.Image = "alpine/edge/amd64" | ||
bravefile.Base.Location = "public" | ||
|
||
bravefile.SystemPackages.Manager = "apk" | ||
bravefile.SystemPackages.System = []string{"htop", "make"} | ||
|
||
runCommand := &shared.RunCommand{} | ||
runCommand.Command = "echo" | ||
runCommand.Args = []string{"Hello World"} | ||
|
||
bravefile.Run = []shared.RunCommand{*runCommand} | ||
|
||
bravefile.PlatformService.Name = "alpine-test" | ||
bravefile.PlatformService.Version = "1.0" | ||
bravefile.PlatformService.Image = "alpine-test-1.0" | ||
|
||
bravefile.PlatformService.Resources.CPU = "1" | ||
bravefile.PlatformService.Resources.RAM = "1GB" | ||
|
||
bravefile.PlatformService.Postdeploy.Run = []shared.RunCommand{ | ||
{ | ||
Command: "echo", | ||
Args: []string{"Hello World"}, | ||
}, | ||
} | ||
|
||
err := host.BuildImage(&bravefile) | ||
if err != nil { | ||
t.Error("host.BuildImage: ", err) | ||
} | ||
|
||
err = host.InitUnit(backend, &bravefile) | ||
if err != nil { | ||
t.Error("host.InitUnit: ", err) | ||
} | ||
|
||
err = host.Postdeploy(&bravefile) | ||
if err != nil { | ||
t.Error("host.Postdeploy: ", err) | ||
} | ||
|
||
err = host.DeleteLocalImage("alpine-test-1.0") | ||
if err != nil { | ||
t.Error("host.DeleteImageByName: ", err) | ||
} | ||
|
||
err = host.StopUnit("alpine-test", backend) | ||
if err != nil { | ||
t.Error("host.StopUnit: ", err) | ||
} | ||
|
||
err = host.StartUnit("alpine-test", backend) | ||
if err != nil { | ||
t.Error("host.StartUnit: ", err) | ||
} | ||
|
||
err = host.DeleteUnit("alpine-test") | ||
if err != nil { | ||
t.Error("host.DeleteUnit: ", err) | ||
} | ||
} | ||
|
||
func Test_ListLocalImages(t *testing.T) { | ||
host := *NewBraveHost() | ||
backend := NewLxd(host.Settings) | ||
|
||
err := host.HostInfo(backend, false) | ||
if err != nil { | ||
t.Error("host.HostInfo: ", err) | ||
} | ||
|
||
err = host.ListLocalImages() | ||
if err != nil { | ||
t.Error("host.ListLocalImages: ", err) | ||
} | ||
} | ||
|
||
func Test_ListUnits(t *testing.T) { | ||
host := *NewBraveHost() | ||
backend := NewLxd(host.Settings) | ||
|
||
err := host.HostInfo(backend, false) | ||
if err != nil { | ||
t.Error("host.HostInfo: ", err) | ||
} | ||
|
||
err = host.ListUnits(backend) | ||
if err != nil { | ||
t.Error("host.ListLocalImages: ", err) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo ">> Installing Bravetools" | ||
cd .. | ||
|