Skip to content

Commit

Permalink
Ensure tests are properly cleaned up
Browse files Browse the repository at this point in the history
[finishes #151803941]

Signed-off-by: Danail Branekov <[email protected]>
  • Loading branch information
Callisto13 authored and danail-branekov committed Oct 11, 2017
1 parent 29aceb1 commit c3f6581
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gqt/runtime_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ var _ = Describe("Runtime Plugin", func() {
config.NetworkPluginExtraArgs = []string{networkPluginArgsFile, os.DevNull, "unused"}
})

AfterEach(func() {
Expect(os.Remove(networkPluginArgsFile)).To(Succeed())
})

JustBeforeEach(func() {
Expect(ioutil.WriteFile(
filepath.Join(client.TmpDir, "runtime-state-output"),
Expand Down
3 changes: 2 additions & 1 deletion properties/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ var _ = Describe("Properties", func() {

tmp, err = os.Open(tmp.Name())
Expect(err).NotTo(HaveOccurred())

var roundtripped properties.Manager
Expect(json.NewDecoder(tmp).Decode(&roundtripped)).To(Succeed())
Expect(tmp.Close()).To(Succeed())
Expect(os.Remove(tmp.Name())).To(Succeed())

val, ok := roundtripped.Get("foo", "bar")
Expect(ok).To(BeTrue())
Expand Down
5 changes: 5 additions & 0 deletions rundmc/runrunc/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ var _ = Describe("Create", func() {
Expect(err).NotTo(HaveOccurred())
_, err = io.Copy(logFile, strings.NewReader(logs))
Expect(err).NotTo(HaveOccurred())
Expect(logFile.Close()).To(Succeed())
return runcExitStatus
})
})

AfterEach(func() {
Expect(os.RemoveAll(bundlePath)).To(Succeed())
})

It("creates the container with runC create", func() {
Expect(runner.Create(logger, bundlePath, "some-id", garden.ProcessIO{})).To(Succeed())

Expand Down
4 changes: 4 additions & 0 deletions rundmc/runrunc/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ var _ = Describe("ExecPreparer", func() {
preparer = runrunc.NewExecPreparer(bundleLoader, users, enver, mkdirer, []string{"foo", "bar", "brains"}, runningAsRoot)
})

AfterEach(func() {
Expect(os.RemoveAll(bundlePath)).To(Succeed())
})

It("passes a process.json with the correct path and args", func() {
spec, err := preparer.Prepare(logger, bundlePath, garden.ProcessSpec{Path: "to enlightenment", Args: []string{"infinity", "and beyond"}})
Expect(err).NotTo(HaveOccurred())
Expand Down
7 changes: 7 additions & 0 deletions rundmc/runrunc/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ var _ = Describe("RunAndLog", func() {
})
})

AfterEach(func() {
if _, err := os.Stat(logFile.Name()); err == nil {
Expect(logFile.Close()).To(Succeed())
Expect(os.Remove(logFile.Name())).To(Succeed())
}
})

It("execs the command", func() {
Expect(logRunner.RunAndLog(logger, func(logFile string) *exec.Cmd {
return exec.Command("something.exe")
Expand Down
1 change: 1 addition & 0 deletions rundmc/stopper/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (r resolver) Resolve(name, subsystem string) (string, error) {
if err != nil {
return "", err
}
defer stateJson.Close()

var s state
if err := json.NewDecoder(stateJson).Decode(&s); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion rundmc/stopper/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = Describe("Resolver", func() {
})

AfterEach(func() {
os.RemoveAll(fakeStateDir)
Expect(os.RemoveAll(fakeStateDir)).To(Succeed())
})

Context("with valid state.json", func() {
Expand Down

0 comments on commit c3f6581

Please sign in to comment.