0
0
forked from toolshed/abra

test: fix imports

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

View File

@ -3,17 +3,59 @@ package app_test
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"path"
"reflect" "reflect"
"testing" "testing"
appPkg "coopcloud.tech/abra/pkg/app" appPkg "coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/abra/pkg/recipe"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert" "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) { func TestNewApp(t *testing.T) {
app, err := appPkg.NewApp(ExpectedAppEnv, AppName, ExpectedAppFile) app, err := appPkg.NewApp(ExpectedAppEnv, AppName, ExpectedAppFile)
if err != nil { if err != nil {
@ -83,7 +125,7 @@ func TestGetComposeFiles(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
composeFiles, err := appPkg.GetComposeFiles(r.Name, test.appEnv) composeFiles, err := recipe.GetComposeFiles(r.Name, test.appEnv)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -104,7 +146,7 @@ func TestGetComposeFilesError(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
_, err := appPkg.GetComposeFiles(r.Name, test.appEnv) _, err := recipe.GetComposeFiles(r.Name, test.appEnv)
if err == nil { if err == nil {
t.Fatalf("should have failed: %v", test.appEnv) t.Fatalf("should have failed: %v", test.appEnv)
} }
@ -118,7 +160,7 @@ func TestFilters(t *testing.T) {
config.RECIPES_DIR = oldDir config.RECIPES_DIR = oldDir
}() }()
app, err := appPkg.NewApp(appPkg.AppEnv{ app, err := appPkg.NewApp(envfile.AppEnv{
"DOMAIN": "test.example.com", "DOMAIN": "test.example.com",
"RECIPE": "test-recipe", "RECIPE": "test-recipe",
}, "test_example_com", appPkg.AppFile{ }, "test_example_com", appPkg.AppFile{

View File

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