chore: restructure unit testing resources
This commit is contained in:
101
pkg/test/test.go
101
pkg/test/test.go
@ -1,6 +1,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@ -11,70 +12,68 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
TestFolder = os.ExpandEnv("$PWD/../../tests/resources/test_folder")
|
||||
ValidAbraConf = os.ExpandEnv("$PWD/../../tests/resources/valid_abra_config")
|
||||
AppName = "test_app.example.com"
|
||||
ServerName = "test_server"
|
||||
TFiles = []string{"bar.env", "foo.env"}
|
||||
TFolders = []string{"dir1", "dir2"}
|
||||
TestServer = os.ExpandEnv("$PWD/../../tests/resources/test_server")
|
||||
TestDir = os.ExpandEnv("$PWD/../../tests/resources/test_dir")
|
||||
|
||||
ExpectedAppEnv = envfile.AppEnv{
|
||||
"DOMAIN": "test_app.example.com",
|
||||
"RECIPE": "test_recipe",
|
||||
}
|
||||
|
||||
ExpectedApp = appPkg.App{
|
||||
Name: AppName,
|
||||
Recipe: recipe.Get(ExpectedAppEnv["RECIPE"]),
|
||||
Domain: ExpectedAppEnv["DOMAIN"],
|
||||
Env: ExpectedAppEnv,
|
||||
Path: ExpectedAppFile.Path,
|
||||
Server: ExpectedAppFile.Server,
|
||||
}
|
||||
|
||||
ExpectedAppFile = appPkg.AppFile{
|
||||
Path: path.Join(TestServer, fmt.Sprintf("%s.env", AppName)),
|
||||
Server: ServerName,
|
||||
}
|
||||
|
||||
ExpectedAppFiles = map[string]appPkg.AppFile{
|
||||
AppName: ExpectedAppFile,
|
||||
}
|
||||
)
|
||||
|
||||
// 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",
|
||||
"SMTP_AUTHTYPE": "login",
|
||||
}
|
||||
|
||||
var ExpectedApp = appPkg.App{
|
||||
Name: AppName,
|
||||
Recipe: recipe.Get(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,
|
||||
}
|
||||
|
||||
// RmServerAppRecipe deletes the test server / app / recipe.
|
||||
func RmServerAppRecipe() {
|
||||
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
|
||||
if err := os.Remove(testAppLink); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
testAppLink := os.ExpandEnv("$ABRA_DIR/servers/test_server")
|
||||
os.Remove(testAppLink)
|
||||
|
||||
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
|
||||
if err := os.Remove(testRecipeLink); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
testRecipeLink := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
|
||||
os.Remove(testRecipeLink)
|
||||
}
|
||||
|
||||
// MkServerAppRecipe symlinks the test server / app / recipe.
|
||||
func MkServerAppRecipe() {
|
||||
RmServerAppRecipe()
|
||||
|
||||
testAppDir := os.ExpandEnv("$PWD/../../tests/resources/testapp")
|
||||
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
|
||||
if err := os.Mkdir(os.ExpandEnv("$ABRA_DIR/servers"), 0700); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Mkdir(os.ExpandEnv("$ABRA_DIR/recipes"), 0764); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
testAppDir := os.ExpandEnv("$PWD/../../tests/resources/test_server")
|
||||
testAppLink := os.ExpandEnv("$ABRA_DIR/servers/test_server")
|
||||
if err := os.Symlink(testAppDir, testAppLink); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
testRecipeDir := os.ExpandEnv("$PWD/../../tests/resources/testrecipe")
|
||||
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
|
||||
testRecipeDir := os.ExpandEnv("$PWD/../../tests/resources/test_recipe")
|
||||
testRecipeLink := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
|
||||
if err := os.Symlink(testRecipeDir, testRecipeLink); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
6
tests/resources/test_recipe/.env.sample
Normal file
6
tests/resources/test_recipe/.env.sample
Normal file
@ -0,0 +1,6 @@
|
||||
RECIPE=test_recipe
|
||||
DOMAIN=test_app.example.com
|
||||
|
||||
# NOTE(d1): ensure commented out TIMEOUT doesn't get included
|
||||
# see TestReadEnv in ./pkg/envfile
|
||||
# TIMEOUT=120
|
15
tests/resources/test_recipe/compose.yml
Normal file
15
tests/resources/test_recipe/compose.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
app:
|
||||
image: nginx:1.29.0
|
||||
networks:
|
||||
- proxy
|
||||
deploy:
|
||||
labels:
|
||||
- "coop-cloud.${STACK_NAME}.timeout=${TIMEOUT}"
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
6
tests/resources/test_server/test_app.example.com.env
Normal file
6
tests/resources/test_server/test_app.example.com.env
Normal file
@ -0,0 +1,6 @@
|
||||
RECIPE=test_recipe
|
||||
DOMAIN=test_app.example.com
|
||||
|
||||
# NOTE(d1): ensure commented out TIMEOUT doesn't get included
|
||||
# see TestReadEnv in ./pkg/envfile
|
||||
# TIMEOUT=120
|
@ -1,3 +0,0 @@
|
||||
RECIPE=ecloud
|
||||
DOMAIN=ecloud.evil.corp
|
||||
SMTP_AUTHTYPE=login
|
Reference in New Issue
Block a user