81 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package test
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"path"
 | |
| 
 | |
| 	appPkg "coopcloud.tech/abra/pkg/app"
 | |
| 	"coopcloud.tech/abra/pkg/envfile"
 | |
| 	"coopcloud.tech/abra/pkg/log"
 | |
| 	"coopcloud.tech/abra/pkg/recipe"
 | |
| )
 | |
| 
 | |
| var (
 | |
| 	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,
 | |
| 	}
 | |
| )
 | |
| 
 | |
| func RmServerAppRecipe() {
 | |
| 	testAppLink := os.ExpandEnv("$ABRA_DIR/servers/test_server")
 | |
| 	os.Remove(testAppLink)
 | |
| 
 | |
| 	testRecipeLink := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
 | |
| 	os.Remove(testRecipeLink)
 | |
| }
 | |
| 
 | |
| func MkServerAppRecipe() {
 | |
| 	RmServerAppRecipe()
 | |
| 
 | |
| 	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/test_recipe")
 | |
| 	testRecipeLink := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
 | |
| 	if err := os.Symlink(testRecipeDir, testRecipeLink); err != nil {
 | |
| 		log.Fatal(err)
 | |
| 	}
 | |
| }
 |