chore: restructure unit testing resources
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@ -11,28 +12,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TestFolder = os.ExpandEnv("$PWD/../../tests/resources/test_folder")
|
AppName = "test_app.example.com"
|
||||||
ValidAbraConf = os.ExpandEnv("$PWD/../../tests/resources/valid_abra_config")
|
ServerName = "test_server"
|
||||||
)
|
|
||||||
|
|
||||||
// make sure these are in alphabetical order
|
|
||||||
var (
|
|
||||||
TFolders = []string{"folder1", "folder2"}
|
|
||||||
TFiles = []string{"bar.env", "foo.env"}
|
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")
|
||||||
|
|
||||||
var (
|
ExpectedAppEnv = envfile.AppEnv{
|
||||||
AppName = "ecloud"
|
"DOMAIN": "test_app.example.com",
|
||||||
ServerName = "evil.corp"
|
"RECIPE": "test_recipe",
|
||||||
)
|
|
||||||
|
|
||||||
var ExpectedAppEnv = envfile.AppEnv{
|
|
||||||
"DOMAIN": "ecloud.evil.corp",
|
|
||||||
"RECIPE": "ecloud",
|
|
||||||
"SMTP_AUTHTYPE": "login",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ExpectedApp = appPkg.App{
|
ExpectedApp = appPkg.App{
|
||||||
Name: AppName,
|
Name: AppName,
|
||||||
Recipe: recipe.Get(ExpectedAppEnv["RECIPE"]),
|
Recipe: recipe.Get(ExpectedAppEnv["RECIPE"]),
|
||||||
Domain: ExpectedAppEnv["DOMAIN"],
|
Domain: ExpectedAppEnv["DOMAIN"],
|
||||||
@ -41,40 +33,47 @@ var ExpectedApp = appPkg.App{
|
|||||||
Server: ExpectedAppFile.Server,
|
Server: ExpectedAppFile.Server,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ExpectedAppFile = appPkg.AppFile{
|
ExpectedAppFile = appPkg.AppFile{
|
||||||
Path: path.Join(ValidAbraConf, "servers", ServerName, AppName+".env"),
|
Path: path.Join(TestServer, fmt.Sprintf("%s.env", AppName)),
|
||||||
Server: ServerName,
|
Server: ServerName,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ExpectedAppFiles = map[string]appPkg.AppFile{
|
ExpectedAppFiles = map[string]appPkg.AppFile{
|
||||||
AppName: ExpectedAppFile,
|
AppName: ExpectedAppFile,
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// RmServerAppRecipe deletes the test server / app / recipe.
|
|
||||||
func RmServerAppRecipe() {
|
func RmServerAppRecipe() {
|
||||||
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
|
testAppLink := os.ExpandEnv("$ABRA_DIR/servers/test_server")
|
||||||
if err := os.Remove(testAppLink); err != nil {
|
os.Remove(testAppLink)
|
||||||
log.Fatal(err)
|
|
||||||
|
testRecipeLink := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
|
||||||
|
os.Remove(testRecipeLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
|
|
||||||
if err := os.Remove(testRecipeLink); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MkServerAppRecipe symlinks the test server / app / recipe.
|
|
||||||
func MkServerAppRecipe() {
|
func MkServerAppRecipe() {
|
||||||
RmServerAppRecipe()
|
RmServerAppRecipe()
|
||||||
|
|
||||||
testAppDir := os.ExpandEnv("$PWD/../../tests/resources/testapp")
|
if err := os.Mkdir(os.ExpandEnv("$ABRA_DIR/servers"), 0700); err != nil {
|
||||||
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
|
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 {
|
if err := os.Symlink(testAppDir, testAppLink); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
testRecipeDir := os.ExpandEnv("$PWD/../../tests/resources/testrecipe")
|
testRecipeDir := os.ExpandEnv("$PWD/../../tests/resources/test_recipe")
|
||||||
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
|
testRecipeLink := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
|
||||||
if err := os.Symlink(testRecipeDir, testRecipeLink); err != nil {
|
if err := os.Symlink(testRecipeDir, testRecipeLink); err != nil {
|
||||||
log.Fatal(err)
|
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