mirror of
https://github.com/portainer/portainer.git
synced 2025-07-20 22:09:41 +02:00
* feat(compose): add docker-compose wrapper ce-187 * fix(compose): pick compose implementation upon startup * Add static compose build for linux * Fix wget * Fix platofrm specific docker-compose download * Keep amd64 architecture as download parameter * Add tmp folder for docker-compose * fix: line endings * add proxy server * logs * Proxy * Add lite transport for compose * Fix local deployment * refactor: pass proxyManager by ref * fix: string conversion * refactor: compose wrapper remove unused code * fix: tests * Add edge * Fix merge issue * refactor: remove unused code * Move server to proxy implementation * Cleanup wrapper and manager * feat: pass max supported compose syntax version with each endpoint * fix: pick compose syntax version * fix: store wrapper version in portainer * Get and show composeSyntaxMaxVersion at stack creation screen * Get and show composeSyntaxMaxVersion at stack editor screen * refactor: proxy server * Fix used tmp * Bump docker-compose to 1.28.0 * remove message for docker compose limitation * fix: markup typo * Rollback docker compose to 1.27.4 * * attempt to fix the windows build issue * * attempt to debug grunt issue * * use console log in grunt file * fix: try to fix windows build by removing indirect deps from go.mod * Remove tmp folder * Remove builder stage * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose - fixed verbose output * refactor: renames * fix(stack): get endpoint by EndpointProvider * fix(stack): use margin to add space between line instead of using br tag Co-authored-by: Stéphane Busso <stephane.busso@gmail.com> Co-authored-by: Simon Meng <simon.meng@portainer.io> Co-authored-by: yi-portainer <yi.chen@portainer.io> Co-authored-by: Steven Kang <skan070@gmail.com>
143 lines
3.2 KiB
Go
143 lines
3.2 KiB
Go
package exec
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_setComposeFile(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
stack *portainer.Stack
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "should return empty result if stack is missing",
|
|
stack: nil,
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should return empty result if stack don't have entrypoint",
|
|
stack: &portainer.Stack{},
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should allow file name and dir",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: "dir",
|
|
EntryPoint: "file",
|
|
},
|
|
expected: []string{"-f", path.Join("dir", "file")},
|
|
},
|
|
{
|
|
name: "should allow file name only",
|
|
stack: &portainer.Stack{
|
|
EntryPoint: "file",
|
|
},
|
|
expected: []string{"-f", "file"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := setComposeFile(tt.stack)
|
|
assert.ElementsMatch(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_addProjectNameOption(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
stack *portainer.Stack
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "should not add project option if stack is missing",
|
|
stack: nil,
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should not add project option if stack doesn't have name",
|
|
stack: &portainer.Stack{},
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should add project name option if stack has a name",
|
|
stack: &portainer.Stack{
|
|
Name: "project-name",
|
|
},
|
|
expected: []string{"-p", "project-name"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
options := []string{"-a", "b"}
|
|
result := addProjectNameOption(options, tt.stack)
|
|
assert.ElementsMatch(t, append(options, tt.expected...), result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_addEnvFileOption(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
tests := []struct {
|
|
name string
|
|
stack *portainer.Stack
|
|
expected []string
|
|
expectedContent string
|
|
}{
|
|
{
|
|
name: "should not add env file option if stack is missing",
|
|
stack: nil,
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should not add env file option if stack doesn't have env variables",
|
|
stack: &portainer.Stack{},
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should not add env file option if stack's env variables are empty",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: dir,
|
|
Env: []portainer.Pair{},
|
|
},
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "should add env file option if stack has env variables",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: dir,
|
|
Env: []portainer.Pair{
|
|
{Name: "var1", Value: "value1"},
|
|
{Name: "var2", Value: "value2"},
|
|
},
|
|
},
|
|
expected: []string{"--env-file", path.Join(dir, "stack.env")},
|
|
expectedContent: "var1=value1\nvar2=value2\n",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
options := []string{"-a", "b"}
|
|
result, _ := addEnvFileOption(options, tt.stack)
|
|
assert.ElementsMatch(t, append(options, tt.expected...), result)
|
|
|
|
if tt.expectedContent != "" {
|
|
f, _ := os.Open(path.Join(dir, "stack.env"))
|
|
content, _ := ioutil.ReadAll(f)
|
|
|
|
assert.Equal(t, tt.expectedContent, string(content))
|
|
}
|
|
})
|
|
}
|
|
}
|