|
4 | 4 | "io/ioutil"
|
5 | 5 | "os"
|
6 | 6 | "path/filepath"
|
| 7 | + "syscall" |
7 | 8 |
|
8 | 9 | . "code.cloudfoundry.org/cli/util/configv3"
|
9 | 10 | . "github.com/onsi/ginkgo"
|
@@ -382,6 +383,67 @@ var _ = Describe("PluginsConfig", func() {
|
382 | 383 | })
|
383 | 384 | })
|
384 | 385 | })
|
| 386 | + |
| 387 | + Describe("CreatePluginHome", func() { |
| 388 | + var ( |
| 389 | + config *Config |
| 390 | + |
| 391 | + pluginHome string |
| 392 | + |
| 393 | + executeErr error |
| 394 | + ) |
| 395 | + |
| 396 | + BeforeEach(func() { |
| 397 | + config = new(Config) |
| 398 | + |
| 399 | + var err error |
| 400 | + pluginHome, err = ioutil.TempDir("", "my-plugin-home") |
| 401 | + Expect(err).ToNot(HaveOccurred()) |
| 402 | + Expect(os.RemoveAll(pluginHome)).ToNot(HaveOccurred()) |
| 403 | + }) |
| 404 | + |
| 405 | + AfterEach(func() { |
| 406 | + Expect(os.RemoveAll(pluginHome)).ToNot(HaveOccurred()) |
| 407 | + }) |
| 408 | + |
| 409 | + JustBeforeEach(func() { |
| 410 | + executeErr = config.CreatePluginHome() |
| 411 | + }) |
| 412 | + |
| 413 | + Context("when it correctly writes a directory", func() { |
| 414 | + BeforeEach(func() { |
| 415 | + config.ENV.CFPluginHome = pluginHome |
| 416 | + }) |
| 417 | + |
| 418 | + It("returns no error", func() { |
| 419 | + Expect(executeErr).ToNot(HaveOccurred()) |
| 420 | + |
| 421 | + _, statErr := os.Stat(pluginHome) |
| 422 | + Expect(os.IsNotExist(statErr)).To(BeFalse()) |
| 423 | + }) |
| 424 | + }) |
| 425 | + |
| 426 | + Context("when it fails to write a directory", func() { |
| 427 | + var tempFile string |
| 428 | + |
| 429 | + BeforeEach(func() { |
| 430 | + f, err := ioutil.TempFile("", "fail-plugin-home") |
| 431 | + Expect(err).ToNot(HaveOccurred()) |
| 432 | + Expect(f.Close()).ToNot(HaveOccurred()) |
| 433 | + tempFile = f.Name() |
| 434 | + |
| 435 | + config.ENV.CFPluginHome = tempFile + "/some-path" |
| 436 | + }) |
| 437 | + |
| 438 | + AfterEach(func() { |
| 439 | + Expect(os.RemoveAll(tempFile)).ToNot(HaveOccurred()) |
| 440 | + }) |
| 441 | + |
| 442 | + It("returns an error", func() { |
| 443 | + Expect(executeErr).To(MatchError(&os.PathError{Op: "mkdir", Path: tempFile, Err: syscall.ENOTDIR})) |
| 444 | + }) |
| 445 | + }) |
| 446 | + }) |
385 | 447 | })
|
386 | 448 |
|
387 | 449 | Describe("Plugin", func() {
|
|
0 commit comments