2021-06-25 17:08:40 +02:00
|
|
|
/*
|
|
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gotest.tools/v3/icmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestComposeMetrics(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
c := NewParallelCLI(t)
|
2021-06-25 17:08:40 +02:00
|
|
|
|
|
|
|
t.Run("catch specific failure metrics", func(t *testing.T) {
|
2022-06-15 21:55:58 +02:00
|
|
|
res := c.RunDockerOrExitError(t, "compose", "-f", "fixtures/does-not-exist/compose.yaml", "build")
|
2021-06-25 17:08:40 +02:00
|
|
|
expectedErr := "fixtures/does-not-exist/compose.yaml: no such file or directory"
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
expectedErr = "does-not-exist\\compose.yaml: The system cannot find the path specified"
|
|
|
|
}
|
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 14, Err: expectedErr})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "-f", "fixtures/wrong-composefile/compose.yaml", "up", "-d")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 15, Err: "services.simple Additional property wrongField is not allowed"})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "up")
|
2021-11-22 17:46:37 +01:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 14, Err: "no configuration file provided: not found"})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "up", "-f", "fixtures/wrong-composefile/compose.yaml")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 16, Err: "unknown shorthand flag: 'f' in -f"})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "up", "--file", "fixtures/wrong-composefile/compose.yaml")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 16, Err: "unknown flag: --file"})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "donw", "--file", "fixtures/wrong-composefile/compose.yaml")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 16, Err: `unknown docker command: "compose donw"`})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "--file", "fixtures/wrong-composefile/build-error.yml", "build")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 17, Err: `line 17: unknown instruction: WRONG`})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "--file", "fixtures/wrong-composefile/build-error.yml", "up")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 17, Err: `line 17: unknown instruction: WRONG`})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "--file", "fixtures/wrong-composefile/unknown-image.yml", "pull")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 18, Err: `pull access denied for unknownimage, repository does not exist or may require 'docker login'`})
|
2022-06-15 21:55:58 +02:00
|
|
|
res = c.RunDockerOrExitError(t, "compose", "--file", "fixtures/wrong-composefile/unknown-image.yml", "up")
|
2021-06-25 17:08:40 +02:00
|
|
|
res.Assert(t, icmd.Expected{ExitCode: 18, Err: `pull access denied for unknownimage, repository does not exist or may require 'docker login'`})
|
|
|
|
})
|
|
|
|
}
|