diff --git a/dependencies/config/config_test.go b/dependencies/config/config_test.go index 3d6c1c6..2d0cd46 100644 --- a/dependencies/config/config_test.go +++ b/dependencies/config/config_test.go @@ -65,8 +65,12 @@ func setupConfigTemplate(templatePath string) error { return nil } -func teardownConfigTemplate(templatePath string) (err error) { - if err := os.RemoveAll(templatePath); err != nil { +func teardownConfigTemplate() (err error) { + if err := os.RemoveAll(templatePrefix); err != nil { + return err + } + + if err := os.RemoveAll(testConfigPath); err != nil { return err } @@ -89,7 +93,7 @@ var _ = Describe("Config", func() { err := teardownOsEnvironment() Expect(err).NotTo(HaveOccurred()) - err = teardownConfigTemplate(testTemplatePath) + err = teardownConfigTemplate() Expect(err).NotTo(HaveOccurred()) }) diff --git a/dependencies/socket/socket_test.go b/dependencies/socket/socket_test.go index 934ed6f..058654e 100644 --- a/dependencies/socket/socket_test.go +++ b/dependencies/socket/socket_test.go @@ -2,7 +2,9 @@ package socket import ( "fmt" + "io/ioutil" "os" + "path/filepath" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -12,21 +14,45 @@ import ( ) const ( - existingSocketPath = "/tmp/k8s-existing-socket" - nonExistingSocketPath = "/tmp/k8s-nonexisting-socket" - noPermsSocketPath = "/root/k8s-no-permission-socket" + tempPathSuffix = "k8s-entrypoint" + + existingSocket = "existing-socket" + nonExistingSocket = "nonexisting-socket" +) + +var ( + testDir string + + existingSocketPath string + nonExistingSocketPath string ) var testEntrypoint entrypoint.EntrypointInterface var _ = Describe("Socket", func() { + // NOTE: It is impossible for a user to create a file that he does not + // have access to, and thus it is impossible to write an isolated unit + // test that checks for permission errors. That test is omitted from + // this suite + BeforeEach(func() { testEntrypoint = mocks.NewEntrypoint() - _, err := os.Create(existingSocketPath) + var err error + testDir, err = ioutil.TempDir("", tempPathSuffix) Expect(err).NotTo(HaveOccurred()) + existingSocketPath = filepath.Join(testDir, existingSocket) + nonExistingSocketPath = filepath.Join(testDir, nonExistingSocket) + + _, err = os.Create(existingSocketPath) + Expect(err).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + err := os.RemoveAll(testDir) + Expect(err).NotTo(HaveOccurred()) }) It("checks the name of a newly created socket", func() { @@ -53,14 +79,4 @@ var _ = Describe("Socket", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal(fmt.Sprintf(NonExistingErrorFormat, socket))) }) - - It("fails on trying to resolve a socket without permissions", func() { - socket := NewSocket(noPermsSocketPath) - - isResolved, err := socket.IsResolved(testEntrypoint) - - Expect(isResolved).To(Equal(false)) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(fmt.Sprintf(NoPermsErrorFormat, socket))) - }) })