-
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 #89 from bravetools/iad-testing
create unit testing framework
- Loading branch information
Showing
4 changed files
with
145 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,107 @@ | ||
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" | ||
|
||
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.DeleteLocalImage("alpine-test-1.0") | ||
if err != nil { | ||
t.Error("host.DeleteImageByName: ", 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 .. | ||
|