Integration test suite first steps... #347
5
Makefile
5
Makefile
@ -15,9 +15,12 @@ run:
|
|||||||
install:
|
install:
|
||||||
@go install -ldflags=$(LDFLAGS) $(ABRA)
|
@go install -ldflags=$(LDFLAGS) $(ABRA)
|
||||||
|
|
||||||
build-dev:
|
build-abra:
|
||||||
@go build -v -ldflags=$(LDFLAGS) $(ABRA)
|
@go build -v -ldflags=$(LDFLAGS) $(ABRA)
|
||||||
|
|
||||||
|
build-kadabra:
|
||||||
|
@go build -v -ldflags=$(LDFLAGS) $(KADABRA)
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@go build -v -ldflags=$(DIST_LDFLAGS) $(ABRA)
|
@go build -v -ldflags=$(DIST_LDFLAGS) $(ABRA)
|
||||||
@go build -v -ldflags=$(DIST_LDFLAGS) $(KADABRA)
|
@go build -v -ldflags=$(DIST_LDFLAGS) $(KADABRA)
|
||||||
|
@ -93,14 +93,14 @@ var appNewCommand = cli.Command{
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cl, err := client.New(internal.NewAppServer)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var secrets AppSecrets
|
var secrets AppSecrets
|
||||||
var secretTable *jsontable.JSONTable
|
var secretTable *jsontable.JSONTable
|
||||||
if internal.Secrets {
|
if internal.Secrets {
|
||||||
|
cl, err := client.New(internal.NewAppServer)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
secrets, err := createSecrets(cl, sanitisedAppName)
|
secrets, err := createSecrets(cl, sanitisedAppName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
17
cli/cli.go
17
cli/cli.go
@ -16,6 +16,7 @@ import (
|
|||||||
"coopcloud.tech/abra/cli/server"
|
"coopcloud.tech/abra/cli/server"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
"coopcloud.tech/abra/pkg/git"
|
||||||
"coopcloud.tech/abra/pkg/web"
|
"coopcloud.tech/abra/pkg/web"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@ -170,10 +171,10 @@ func newAbraApp(version, commit string) *cli.App {
|
|||||||
app.Before = func(c *cli.Context) error {
|
app.Before = func(c *cli.Context) error {
|
||||||
paths := []string{
|
paths := []string{
|
||||||
config.ABRA_DIR,
|
config.ABRA_DIR,
|
||||||
path.Join(config.SERVERS_DIR),
|
config.SERVERS_DIR,
|
||||||
path.Join(config.RECIPES_DIR),
|
config.RECIPES_DIR,
|
||||||
path.Join(config.VENDOR_DIR),
|
config.VENDOR_DIR,
|
||||||
path.Join(config.BACKUP_DIR),
|
config.BACKUP_DIR,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range paths {
|
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)
|
logrus.Debugf("abra version %s, commit %s", version, commit)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -14,7 +14,16 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"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
|
|||||||
|
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 SERVERS_DIR = path.Join(ABRA_DIR, "servers")
|
||||||
var RECIPES_DIR = path.Join(ABRA_DIR, "recipes")
|
var RECIPES_DIR = path.Join(ABRA_DIR, "recipes")
|
||||||
var VENDOR_DIR = path.Join(ABRA_DIR, "vendor")
|
var VENDOR_DIR = path.Join(ABRA_DIR, "vendor")
|
||||||
|
51
tests/integration/dirs.bats
Normal file
51
tests/integration/dirs.bats
Normal 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
|
||||||
|
}
|
35
tests/integration/helpers.sh
Normal file
35
tests/integration/helpers.sh
Normal 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
|
||||||
decentral1se marked this conversation as resolved
Outdated
decentral1se
commented
Oops, that's wrong, Need a dedicated Oops, that's wrong, Need a dedicated `kadabra` makefile target. TODO 🤓
|
|||||||
|
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"
|
||||||
|
}
|
33
tests/integration/recipe.bats
Normal file
33
tests/integration/recipe.bats
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user
What about making the env var
ABRA_DIR
, and defaulting to$HOME/.abra
? then for testsABRA_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.