forked from toolshed/abra
fix: validate COMPOSE_FILE
See coop-cloud/organising#468. See coop-cloud/organising#376.
This commit is contained in:
@ -1,12 +1,22 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"coopcloud.tech/abra/pkg/catalogue"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func setup(t *testing.T) {
|
||||
if err := catalogue.EnsureCatalogue(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewApp(t *testing.T) {
|
||||
app, err := config.NewApp(ExpectedAppEnv, AppName, ExpectedAppFile)
|
||||
if err != nil {
|
||||
@ -36,3 +46,74 @@ func TestGetApp(t *testing.T) {
|
||||
t.Fatalf("did not get expected app type. Expected: %s; Got: %s", app, ExpectedApp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetComposeFiles(t *testing.T) {
|
||||
setup(t)
|
||||
|
||||
offline := true
|
||||
r, err := recipe.Get("abra-integration-test-recipe", offline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
appEnv map[string]string
|
||||
composeFiles []string
|
||||
}{
|
||||
{
|
||||
map[string]string{},
|
||||
[]string{
|
||||
fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
|
||||
},
|
||||
},
|
||||
{
|
||||
map[string]string{"COMPOSE_FILE": "compose.yml"},
|
||||
[]string{
|
||||
fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
|
||||
},
|
||||
},
|
||||
{
|
||||
map[string]string{"COMPOSE_FILE": "compose.extra_secret.yml"},
|
||||
[]string{
|
||||
fmt.Sprintf("%s/%s/compose.extra_secret.yml", config.RECIPES_DIR, r.Name),
|
||||
},
|
||||
},
|
||||
{
|
||||
map[string]string{"COMPOSE_FILE": "compose.yml:compose.extra_secret.yml"},
|
||||
[]string{
|
||||
fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, r.Name),
|
||||
fmt.Sprintf("%s/%s/compose.extra_secret.yml", config.RECIPES_DIR, r.Name),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
composeFiles, err := config.GetComposeFiles(r.Name, test.appEnv)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, composeFiles, test.composeFiles)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetComposeFilesError(t *testing.T) {
|
||||
setup(t)
|
||||
|
||||
offline := true
|
||||
r, err := recipe.Get("abra-integration-test-recipe", offline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct{ appEnv map[string]string }{
|
||||
{map[string]string{"COMPOSE_FILE": "compose.yml::compose.foo.yml"}},
|
||||
{map[string]string{"COMPOSE_FILE": "doesnt.exist.yml"}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
_, err := config.GetComposeFiles(r.Name, test.appEnv)
|
||||
if err == nil {
|
||||
t.Fatalf("should have failed: %v", test.appEnv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user