Merge pull request #1326 from greut/add-to-err-on-404
add should fail on 40x
This commit is contained in:
commit
92917bab3a
|
|
@ -0,0 +1,4 @@
|
||||||
|
FROM debian:9.11
|
||||||
|
|
||||||
|
# Testing that any HTTP failure is handled properly
|
||||||
|
ADD https://httpstat.us/404 .
|
||||||
|
|
@ -167,6 +167,7 @@ type DockerFileBuilder struct {
|
||||||
func NewDockerFileBuilder() *DockerFileBuilder {
|
func NewDockerFileBuilder() *DockerFileBuilder {
|
||||||
d := DockerFileBuilder{filesBuilt: map[string]struct{}{}}
|
d := DockerFileBuilder{filesBuilt: map[string]struct{}{}}
|
||||||
d.DockerfilesToIgnore = map[string]struct{}{
|
d.DockerfilesToIgnore = map[string]struct{}{
|
||||||
|
"Dockerfile_test_add_404": {},
|
||||||
// TODO: remove test_user_run from this when https://github.com/GoogleContainerTools/container-diff/issues/237 is fixed
|
// TODO: remove test_user_run from this when https://github.com/GoogleContainerTools/container-diff/issues/237 is fixed
|
||||||
"Dockerfile_test_user_run": {},
|
"Dockerfile_test_user_run": {},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -386,6 +386,40 @@ func TestBuildWithLabels(t *testing.T) {
|
||||||
checkContainerDiffOutput(t, diff, expected)
|
checkContainerDiffOutput(t, diff, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildWithHTTPError(t *testing.T) {
|
||||||
|
repo := getGitRepo()
|
||||||
|
dockerfile := fmt.Sprintf("%s/%s/Dockerfile_test_add_404", integrationPath, dockerfilesPath)
|
||||||
|
|
||||||
|
// Build with docker
|
||||||
|
dockerImage := GetDockerImage(config.imageRepo, "Dockerfile_test_add_404")
|
||||||
|
dockerCmd := exec.Command("docker",
|
||||||
|
append([]string{"build",
|
||||||
|
"-t", dockerImage,
|
||||||
|
"-f", dockerfile,
|
||||||
|
repo})...)
|
||||||
|
out, err := RunCommandWithoutTest(dockerCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("an error was expected, got %s", string(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build with kaniko
|
||||||
|
kanikoImage := GetKanikoImage(config.imageRepo, "Dockerfile_test_add_404")
|
||||||
|
dockerRunFlags := []string{"run", "--net=host"}
|
||||||
|
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount)
|
||||||
|
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
|
||||||
|
"-f", dockerfile,
|
||||||
|
"-d", kanikoImage,
|
||||||
|
"-c", fmt.Sprintf("git://%s", repo),
|
||||||
|
)
|
||||||
|
|
||||||
|
kanikoCmd := exec.Command("docker", dockerRunFlags...)
|
||||||
|
|
||||||
|
out, err = RunCommandWithoutTest(kanikoCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("an error was expected, got %s", string(out))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLayers(t *testing.T) {
|
func TestLayers(t *testing.T) {
|
||||||
offset := map[string]int{
|
offset := map[string]int{
|
||||||
"Dockerfile_test_add": 12,
|
"Dockerfile_test_add": 12,
|
||||||
|
|
|
||||||
|
|
@ -545,6 +545,11 @@ func DownloadFileToDest(rawurl, dest string, uid, gid int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode >= 400 {
|
||||||
|
return fmt.Errorf("invalid response status %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
if err := CreateFile(dest, resp.Body, 0600, uint32(uid), uint32(gid)); err != nil {
|
if err := CreateFile(dest, resp.Body, 0600, uint32(uid), uint32(gid)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue