Integration test suite first steps... #347

Merged
decentral1se merged 7 commits from integration-tests into main 2023-09-05 09:58:15 +00:00
7 changed files with 151 additions and 11 deletions

View File

@ -15,9 +15,12 @@ run:
install:
@go install -ldflags=$(LDFLAGS) $(ABRA)
build-dev:
build-abra:
@go build -v -ldflags=$(LDFLAGS) $(ABRA)
build-kadabra:
@go build -v -ldflags=$(LDFLAGS) $(KADABRA)
build:
@go build -v -ldflags=$(DIST_LDFLAGS) $(ABRA)
@go build -v -ldflags=$(DIST_LDFLAGS) $(KADABRA)

View File

@ -93,14 +93,14 @@ var appNewCommand = cli.Command{
logrus.Fatal(err)
}
cl, err := client.New(internal.NewAppServer)
if err != nil {
logrus.Fatal(err)
}
var secrets AppSecrets
var secretTable *jsontable.JSONTable
if internal.Secrets {
cl, err := client.New(internal.NewAppServer)
if err != nil {
logrus.Fatal(err)
}
secrets, err := createSecrets(cl, sanitisedAppName)
if err != nil {
logrus.Fatal(err)

View File

@ -16,6 +16,7 @@ import (
"coopcloud.tech/abra/cli/server"
"coopcloud.tech/abra/pkg/autocomplete"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/web"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@ -170,10 +171,10 @@ func newAbraApp(version, commit string) *cli.App {
app.Before = func(c *cli.Context) error {
paths := []string{
config.ABRA_DIR,
path.Join(config.SERVERS_DIR),
path.Join(config.RECIPES_DIR),
path.Join(config.VENDOR_DIR),
path.Join(config.BACKUP_DIR),
config.SERVERS_DIR,
config.RECIPES_DIR,
config.VENDOR_DIR,
config.BACKUP_DIR,
}
for _, path := range paths {
@ -185,6 +186,14 @@ func newAbraApp(version, commit string) *cli.App {
}
}
if _, err := os.Stat(config.CATALOGUE_DIR); os.IsNotExist(err) {
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, config.CATALOGUE_JSON_REPO_NAME)
logrus.Warnf("local recipe catalogue is missing, retrieving now")
if err := git.Clone(config.CATALOGUE_DIR, url); err != nil {
logrus.Fatal(err)
}
}
logrus.Debugf("abra version %s, commit %s", version, commit)
return nil

View File

@ -14,7 +14,16 @@ import (
"github.com/sirupsen/logrus"
)
var ABRA_DIR = os.ExpandEnv("$HOME/.abra")
// getBaseDir retrieves the Abra base directory.
func getBaseDir() string {
home := os.ExpandEnv("$HOME/.abra")
decentral1se marked this conversation as resolved
Review

What about making the env var ABRA_DIR, and defaulting to $HOME/.abra? then for tests ABRA_DIR=$HOME/.abra_test, and folks could also choose to put the directory elsewhere for homedir-neatness reasons, or in the case of an immutable home dir.

What about making the env var `ABRA_DIR`, and defaulting to `$HOME/.abra`? then for tests `ABRA_DIR=$HOME/.abra_test`, and folks could also choose to put the directory elsewhere for homedir-neatness reasons, or in the case of an immutable home dir.
if customAbraDir, exists := os.LookupEnv("ABRA_DIR"); exists && customAbraDir != "" {
home = customAbraDir
}
return home
}
var ABRA_DIR = getBaseDir()
var SERVERS_DIR = path.Join(ABRA_DIR, "servers")
var RECIPES_DIR = path.Join(ABRA_DIR, "recipes")
var VENDOR_DIR = path.Join(ABRA_DIR, "vendor")

View File

@ -0,0 +1,51 @@
#!/usr/bin/env bash
setup() {
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
source "$DIR/helpers.sh"
_setup_env
}
@test "ABRA_DIR can be overriden" {
ABRA_DIR="$HOME/.abra_foo"
run $ABRA app ls
# no servers yet, so will fail. however, it will run the required code which
# checks if it should create these base directories and that is what we want
assert_failure
assert [ -d "$HOME/.abra_foo" ]
}
@test "abra directories created" {
run $ABRA app ls
# no servers yet, so will fail. however, it will run the required code which
# checks if it should create these base directories and that is what we want
assert_failure
assert [ -d "$ABRA_DIR" ]
assert [ -d "$ABRA_DIR/servers" ]
assert [ -d "$ABRA_DIR/recipes" ]
assert [ -d "$ABRA_DIR/backups" ]
assert [ -d "$ABRA_DIR/vendor" ]
assert [ -d "$ABRA_DIR/catalogue" ]
}
@test "catalogue recipe is a git repository" {
run $ABRA app ls
# no servers yet, so will fail. however, it will run the required code which
# checks if it should create these base directories and that is what we want
assert_failure
assert_output --partial 'local recipe catalogue is missing'
assert [ -d "$ABRA_DIR/catalogue" ]
assert [ -d "$ABRA_DIR/catalogue/.git" ]
}
teardown(){
_default_teardown
}

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
_build_abra() {
if [[ ! -e "$ROOT/abra" ]]; then
cd "$ROOT" && make build-abra
return 0
fi
return 0
}
_build_kadabra() {
if [[ ! -e "$ROOT/kadabra" ]]; then
cd "$ROOT" && make build-kadabra
return 0
fi
return 0
}
_setup_env(){
load '/usr/lib/bats/bats-support/load'
load '/usr/lib/bats/bats-assert/load'
ROOT="$DIR/../.."
ABRA="$ROOT/abra"
KADABRA="$ROOT/kadabra"
ABRA_DIR="$HOME/.abra_test"
_build_abra
_build_kadabra
}
_default_teardown(){
rm -rf "$ABRA_DIR"
}

View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
setup() {
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
source "$DIR/helpers.sh"
_setup_env
mkdir -p "$HOME/.abra_test/servers/example.com"
if ! grep -R -q "example.com" "$HOME/.docker"; then
docker context create --docker host=ssh://foo@example.com:222 example.com
fi
}
@test "create new recipe" {
run $ABRA recipe new foobar
assert_success
assert_output --partial 'Your new foobar recipe has been created'
run $ABRA app new foobar \
--no-input \
--server example.com \
--domain foobar.example.com
assert_success
assert_output --partial 'A new foobar app has been created!'
}
teardown() {
_default_teardown
if grep -R -q "example.com" "$HOME/.docker"; then
docker context rm example.com
fi
}