Skip to content

Commit

Permalink
Merge pull request #92 from bravetools/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
idroz committed Jun 20, 2022
2 parents c3e7939 + 9f6af59 commit 9f2659b
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
16 changes: 16 additions & 0 deletions macpine/README.md
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 ./...
```
21 changes: 21 additions & 0 deletions macpine/bootstrap.sh
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
164 changes: 164 additions & 0 deletions platform/host_api_test.go
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)
}
}
1 change: 1 addition & 0 deletions test/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

echo ">> Installing Bravetools"
cd ..
Expand Down

0 comments on commit 9f2659b

Please sign in to comment.