From 96e907348ac901e3323ee83cae1b1efd86e4c327 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 29 Apr 2019 20:47:14 +0300 Subject: [PATCH] kubeadm: remove flaky unit tests for chroot This unit test contains some hacks are causing the bazel-test e2e job to flake very often. Instead of maintaining this unit test remove it completely. It has little benefits WRT testing app/util/chroot*.go. --- cmd/kubeadm/app/util/BUILD | 1 - cmd/kubeadm/app/util/chroot_test.go | 66 ----------------------------- 2 files changed, 67 deletions(-) delete mode 100644 cmd/kubeadm/app/util/chroot_test.go diff --git a/cmd/kubeadm/app/util/BUILD b/cmd/kubeadm/app/util/BUILD index f2087e045f6..a4de2a1f7a7 100644 --- a/cmd/kubeadm/app/util/BUILD +++ b/cmd/kubeadm/app/util/BUILD @@ -46,7 +46,6 @@ go_test( srcs = [ "arguments_test.go", "cgroupdriver_test.go", - "chroot_test.go", "endpoint_test.go", "error_test.go", "marshal_test.go", diff --git a/cmd/kubeadm/app/util/chroot_test.go b/cmd/kubeadm/app/util/chroot_test.go deleted file mode 100644 index bb99f03c404..00000000000 --- a/cmd/kubeadm/app/util/chroot_test.go +++ /dev/null @@ -1,66 +0,0 @@ -// +build !windows - -/* -Copyright 2018 The Kubernetes 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 util - -import ( - "os" - "os/exec" - "path/filepath" - "strings" - "testing" -) - -// Can't just call Chroot() because it will affect other tests in the -// same process. Golang makes it hard to just call fork(), so instead -// we exec ourselves again, and run the test in the new subprocess. - -func testChrootReal(t *testing.T) { - testfile := filepath.FromSlash("/" + filepath.Base(os.Args[0])) - dir := filepath.Dir(os.Args[0]) - if dir == "." { - t.Skip("skipping: running test at root somehow") - } - if err := Chroot(dir); err != nil { - if strings.Contains(err.Error(), "operation not permitted") { - t.Skip("skipping: insufficient permissions to chroot") - } - t.Fatalf("chroot error: %v", err) - } - - // All file access should now be relative to `dir` - if _, err := os.Stat(testfile); err != nil { - t.Errorf("Expected file %q to exist, but got %v", testfile, err) - } -} - -func TestChroot(t *testing.T) { - if os.Getenv("GO_TEST_CHROOT_FOR_REALZ") == "1" { - testChrootReal(t) - return - } - - cmd := exec.Command(os.Args[0], "-test.v", "-test.run=TestChroot") - cmd.Env = []string{"GO_TEST_CHROOT_FOR_REALZ=1"} - - out, err := cmd.Output() - t.Logf("subprocess output:\n%s", out) - if err != nil { - t.Errorf("subprocess error: %v", err) - } -}