|
|
@ -35,17 +35,14 @@ services:
|
|
|
|
|
|
|
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
|
|
filePathOriginal, err := createFile(dir, "docker-compose.yml", composeFileContent)
|
|
|
|
filePathOriginal := createFile(t, dir, "docker-compose.yml", composeFileContent)
|
|
|
|
require.NoError(t, err)
|
|
|
|
filePathOverride := createFile(t, dir, "docker-compose-override.yml", overrideComposeFileContent)
|
|
|
|
|
|
|
|
|
|
|
|
filePathOverride, err := createFile(dir, "docker-compose-override.yml", overrideComposeFileContent)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filePaths := []string{filePathOriginal, filePathOverride}
|
|
|
|
filePaths := []string{filePathOriginal, filePathOverride}
|
|
|
|
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
|
|
err = w.Validate(ctx, filePaths, libstack.Options{ProjectName: projectName})
|
|
|
|
err := w.Validate(ctx, filePaths, libstack.Options{ProjectName: projectName})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
err = w.Pull(ctx, filePaths, libstack.Options{ProjectName: projectName})
|
|
|
|
err = w.Pull(ctx, filePaths, libstack.Options{ProjectName: projectName})
|
|
|
@ -73,14 +70,33 @@ services:
|
|
|
|
require.False(t, containerExists(composeContainerName))
|
|
|
|
require.False(t, containerExists(composeContainerName))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func createFile(dir, fileName, content string) (string, error) {
|
|
|
|
func TestRun(t *testing.T) {
|
|
|
|
|
|
|
|
w := NewComposeDeployer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filePath := createFile(t, t.TempDir(), "docker-compose.yml", `
|
|
|
|
|
|
|
|
services:
|
|
|
|
|
|
|
|
updater:
|
|
|
|
|
|
|
|
image: alpine
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filePaths := []string{filePath}
|
|
|
|
|
|
|
|
serviceName := "updater"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := w.Run(context.Background(), filePaths, serviceName, libstack.RunOptions{
|
|
|
|
|
|
|
|
Options: libstack.Options{
|
|
|
|
|
|
|
|
ProjectName: "project_name",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func createFile(t *testing.T, dir, fileName, content string) string {
|
|
|
|
filePath := filepath.Join(dir, fileName)
|
|
|
|
filePath := filepath.Join(dir, fileName)
|
|
|
|
|
|
|
|
|
|
|
|
if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
|
|
|
|
err := os.WriteFile(filePath, []byte(content), 0o644)
|
|
|
|
return "", err
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return filePath, nil
|
|
|
|
return filePath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func containerExists(containerName string) bool {
|
|
|
|
func containerExists(containerName string) bool {
|
|
|
@ -101,8 +117,7 @@ func Test_Validate(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
|
|
filePathOriginal, err := createFile(dir, "docker-compose.yml", invalidComposeFileContent)
|
|
|
|
filePathOriginal := createFile(t, dir, "docker-compose.yml", invalidComposeFileContent)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filePaths := []string{filePathOriginal}
|
|
|
|
filePaths := []string{filePathOriginal}
|
|
|
|
|
|
|
|
|
|
|
@ -110,7 +125,7 @@ func Test_Validate(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
|
|
err = w.Validate(ctx, filePaths, libstack.Options{ProjectName: projectName})
|
|
|
|
err := w.Validate(ctx, filePaths, libstack.Options{ProjectName: projectName})
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -308,13 +323,11 @@ networks:
|
|
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
composeFilePath, err := createFile(dir, "docker-compose.yml", tc.composeFileContent)
|
|
|
|
composeFilePath := createFile(t, dir, "docker-compose.yml", tc.composeFileContent)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
envFilePath := ""
|
|
|
|
envFilePath := ""
|
|
|
|
if tc.envFileContent != "" {
|
|
|
|
if tc.envFileContent != "" {
|
|
|
|
envFilePath, err = createFile(dir, "stack.env", tc.envFileContent)
|
|
|
|
envFilePath = createFile(t, dir, "stack.env", tc.envFileContent)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
w := NewComposeDeployer()
|
|
|
|
w := NewComposeDeployer()
|
|
|
|