test: fix imports

This commit is contained in:
decentral1se 2024-07-07 12:03:37 +02:00
parent 0076b31253
commit c5211fbd7e
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 59 additions and 17 deletions

View File

@ -3,17 +3,59 @@ package app_test
import (
"encoding/json"
"fmt"
"os"
"path"
"reflect"
"testing"
appPkg "coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/recipe"
"github.com/docker/docker/api/types/filters"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)
var (
TestFolder = os.ExpandEnv("$PWD/../../tests/resources/test_folder")
ValidAbraConf = os.ExpandEnv("$PWD/../../tests/resources/valid_abra_config")
)
// make sure these are in alphabetical order
var (
TFolders = []string{"folder1", "folder2"}
TFiles = []string{"bar.env", "foo.env"}
)
var (
AppName = "ecloud"
ServerName = "evil.corp"
)
var ExpectedAppEnv = envfile.AppEnv{
"DOMAIN": "ecloud.evil.corp",
"RECIPE": "ecloud",
}
var ExpectedApp = appPkg.App{
Name: AppName,
Recipe: ExpectedAppEnv["RECIPE"],
Domain: ExpectedAppEnv["DOMAIN"],
Env: ExpectedAppEnv,
Path: ExpectedAppFile.Path,
Server: ExpectedAppFile.Server,
}
var ExpectedAppFile = appPkg.AppFile{
Path: path.Join(ValidAbraConf, "servers", ServerName, AppName+".env"),
Server: ServerName,
}
var ExpectedAppFiles = map[string]appPkg.AppFile{
AppName: ExpectedAppFile,
}
func TestNewApp(t *testing.T) {
app, err := appPkg.NewApp(ExpectedAppEnv, AppName, ExpectedAppFile)
if err != nil {
@ -83,7 +125,7 @@ func TestGetComposeFiles(t *testing.T) {
}
for _, test := range tests {
composeFiles, err := appPkg.GetComposeFiles(r.Name, test.appEnv)
composeFiles, err := recipe.GetComposeFiles(r.Name, test.appEnv)
if err != nil {
t.Fatal(err)
}
@ -104,7 +146,7 @@ func TestGetComposeFilesError(t *testing.T) {
}
for _, test := range tests {
_, err := appPkg.GetComposeFiles(r.Name, test.appEnv)
_, err := recipe.GetComposeFiles(r.Name, test.appEnv)
if err == nil {
t.Fatalf("should have failed: %v", test.appEnv)
}
@ -118,7 +160,7 @@ func TestFilters(t *testing.T) {
config.RECIPES_DIR = oldDir
}()
app, err := appPkg.NewApp(appPkg.AppEnv{
app, err := appPkg.NewApp(envfile.AppEnv{
"DOMAIN": "test.example.com",
"RECIPE": "test-recipe",
}, "test_example_com", appPkg.AppFile{

View File

@ -9,9 +9,9 @@ import (
"strings"
"testing"
"coopcloud.tech/abra/pkg/app"
appPkg "coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/recipe"
)
@ -31,12 +31,12 @@ var (
ServerName = "evil.corp"
)
var ExpectedAppEnv = app.AppEnv{
var ExpectedAppEnv = envfile.AppEnv{
"DOMAIN": "ecloud.evil.corp",
"RECIPE": "ecloud",
}
var ExpectedApp = app.App{
var ExpectedApp = appPkg.App{
Name: AppName,
Recipe: ExpectedAppEnv["RECIPE"],
Domain: ExpectedAppEnv["DOMAIN"],
@ -45,12 +45,12 @@ var ExpectedApp = app.App{
Server: ExpectedAppFile.Server,
}
var ExpectedAppFile = app.AppFile{
var ExpectedAppFile = appPkg.AppFile{
Path: path.Join(ValidAbraConf, "servers", ServerName, AppName+".env"),
Server: ServerName,
}
var ExpectedAppFiles = map[string]app.AppFile{
var ExpectedAppFiles = map[string]appPkg.AppFile{
AppName: ExpectedAppFile,
}
@ -79,7 +79,7 @@ func TestGetAllFilesInDirectory(t *testing.T) {
}
func TestReadEnv(t *testing.T) {
env, err := app.ReadEnv(ExpectedAppFile.Path)
env, err := envfile.ReadEnv(ExpectedAppFile.Path)
if err != nil {
t.Fatal(err)
}
@ -102,7 +102,7 @@ func TestReadAbraShEnvVars(t *testing.T) {
}
abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
abraShEnv, err := app.ReadAbraShEnvVars(abraShPath)
abraShEnv, err := envfile.ReadAbraShEnvVars(abraShPath)
if err != nil {
t.Fatal(err)
}
@ -132,7 +132,7 @@ func TestReadAbraShCmdNames(t *testing.T) {
}
abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
cmdNames, err := app.ReadAbraShCmdNames(abraShPath)
cmdNames, err := appPkg.ReadAbraShCmdNames(abraShPath)
if err != nil {
t.Fatal(err)
}
@ -157,12 +157,12 @@ func TestCheckEnv(t *testing.T) {
}
envSamplePath := path.Join(config.RECIPES_DIR, r.Name, ".env.sample")
envSample, err := app.ReadEnv(envSamplePath)
envSample, err := envfile.ReadEnv(envSamplePath)
if err != nil {
t.Fatal(err)
}
app := app.App{
app := appPkg.App{
Name: "test-app",
Recipe: r.Name,
Domain: "example.com",
@ -191,14 +191,14 @@ func TestCheckEnvError(t *testing.T) {
}
envSamplePath := path.Join(config.RECIPES_DIR, r.Name, ".env.sample")
envSample, err := app.ReadEnv(envSamplePath)
envSample, err := envfile.ReadEnv(envSamplePath)
if err != nil {
t.Fatal(err)
}
delete(envSample, "DOMAIN")
app := app.App{
app := appPkg.App{
Name: "test-app",
Recipe: r.Name,
Domain: "example.com",
@ -227,7 +227,7 @@ func TestEnvVarCommentsRemoved(t *testing.T) {
}
envSamplePath := path.Join(config.RECIPES_DIR, r.Name, ".env.sample")
envSample, err := app.ReadEnv(envSamplePath)
envSample, err := envfile.ReadEnv(envSamplePath)
if err != nil {
t.Fatal(err)
}
@ -259,7 +259,7 @@ func TestEnvVarModifiersIncluded(t *testing.T) {
}
envSamplePath := path.Join(config.RECIPES_DIR, r.Name, ".env.sample")
envSample, modifiers, err := app.ReadEnvWithModifiers(envSamplePath)
envSample, modifiers, err := envfile.ReadEnvWithModifiers(envSamplePath)
if err != nil {
t.Fatal(err)
}