예제 #1
0
			})

			Context("With a nonexistent parent directory for the config file", func() {
				BeforeEach(func() {
					os.RemoveAll(tempDir)
				})

				Describe("Set account", func() {
					It("Creates a config file with the set account", func() {
						Expect(ReadConfig(nonexistentConfigFile, "")).NotTo(Succeed())
						input := new(bytes.Buffer)
						fmt.Fprintln(input, 12345)
						fmt.Fprintln(input, "us-3.rightscale.com")
						fmt.Fprintln(input, "abcdef1234567890abcdef1234567890abcdef12")
						Expect(Config.SetAccount("production", false, input, buffer)).To(Succeed())
						Expect(buffer.Contents()).To(BeEquivalentTo("Account ID: API endpoint host: Refresh token: "))
						config, err := ioutil.ReadFile(nonexistentConfigFile)
						Expect(err).NotTo(HaveOccurred())
						Expect(config).To(BeEquivalentTo(`login:
  accounts:
    production:
      host: us-3.rightscale.com
      id: 12345
      refresh_token: abcdef1234567890abcdef1234567890abcdef12
  default_account: production
update:
  check: true
`))
					})
				})
			})
예제 #2
0
			emptyScriptMetadata = `# ---
# RightScript Name: Empty
# Description: (put your description here, it can be multiple lines using YAML syntax)
# Inputs: {}
# Attachments: []
# ...
`
			if err := ioutil.WriteFile(emptyScript, nil, 0600); err != nil {
				panic(err)
			}
		})

		It("should add default metadata", func() {
			err := ScaffoldRightScript(emptyScript, false, buffer, true)
			Expect(err).To(Succeed())
			Expect(buffer.Contents()).To(BeEquivalentTo(emptyScript + ": Added metadata\n"))

			script, err := ioutil.ReadFile(emptyScript)
			Expect(err).To(Succeed())
			Expect(script).To(BeEquivalentTo(emptyScriptMetadata))
		})

		It("should create a backup file if desired", func() {
			err := ScaffoldRightScript(emptyScript, true, buffer, true)
			Expect(err).To(Succeed())
			Expect(buffer.Contents()).To(BeEquivalentTo(emptyScript + ": Added metadata\n"))

			script, err := ioutil.ReadFile(emptyScript)
			Expect(err).To(Succeed())
			Expect(script).To(BeEquivalentTo(emptyScriptMetadata))
					Expect(<-exitStatus).To(Equal(uint32(1)))
				})

				itRemovesTheRepo()
			})
		})

		Describe("the docker image for the job", func() {
			BeforeEach(func() {
				rootFS = "debian:jessie"
				cmd = "cat /etc/os-release"
			})

			It("runs the job using the specified docker image", func() {
				<-exitStatus
				Expect(string(output.Contents())).To(ContainSubstring("Debian GNU/Linux 8 (jessie)"))
			})
		})
	})

	Context("when the command returns non-zero exit status", func() {
		BeforeEach(func() {
			cmd = `sh -c "echo hello && exit 2"`
		})

		It("asynchronously writes combined stdout and stderr", func() {
			Eventually(output).Should(gbytes.Say("hello"))
		})

		It("sends the status code", func() {
			Expect(<-exitStatus).To(Equal(uint32(2)))
예제 #4
0
func expectExitInBuffer(timeout time.Duration, session *gexec.Session, outputBuffer *gbytes.Buffer) {
	Eventually(session, timeout).Should(gexec.Exit(0))
	Expect(string(outputBuffer.Contents())).To(HaveSuffix("\n"))
}
예제 #5
0
파일: help_test.go 프로젝트: yingkitw/cli
		cmd.SetDependency(deps, false)

		flagContext = flags.NewFlagContext(cmd.MetaData().Flags)
		fakeFactory = &testreq.FakeReqFactory{}
	})

	AfterEach(func() {
		buffer.Close()
	})

	Context("when no argument is provided", func() {
		It("prints the main help menu of the 'cf' app", func() {
			flagContext.Parse()
			cmd.Execute(flagContext)

			Eventually(buffer.Contents()).Should(ContainSubstring("A command line tool to interact with Cloud Foundry"))
			Eventually(buffer).Should(gbytes.Say("CF_TRACE=true"))
		})
	})

	Context("when a command name is provided as an argument", func() {
		Context("When the command exists", func() {
			It("prints the usage help for the command", func() {
				flagContext.Parse("target")
				cmd.Execute(flagContext)

				Expect(fakeUI.SayCallCount()).To(Equal(1))
				output, _ := fakeUI.SayArgsForCall(0)
				Expect(output).To(ContainSubstring("target - Set or view the targeted org or space"))
			})
		})
예제 #6
0
		})

		It("prints its payload", func() {
			Ω(out).Should(gbytes.Say("hello"))
		})
	})

	Context("when an Error event is received", func() {
		BeforeEach(func() {
			receivedEvents <- event.Error{
				Message: "oh no!",
			}
		})

		It("prints its message in bold red, followed by a linebreak", func() {
			Ω(out.Contents()).Should(ContainSubstring(ansi.Color("oh no!", "red+b") + "\n"))
		})
	})

	Context("when an InitializeTask event is received", func() {
		BeforeEach(func() {
			receivedEvents <- event.InitializeTask{
				TaskConfig: event.TaskConfig{
					Image: "some-image",
					Run: event.TaskRunConfig{
						Path: "/some/script",
						Args: []string{"arg1", "arg2"},
					},
				},
			}
		})
예제 #7
0
	BeforeEach(func() {
		stdout = gbytes.NewBuffer()
		cmd := exec.Command("bash", "-c", `
		trap "echo TERMed; exit" TERM
		echo "pid = $$"
		sleep 2
	`)
		cmd.Stdout = io.MultiWriter(stdout, GinkgoWriter)
		cmd.Stderr = GinkgoWriter

		err := cmd.Start()
		Expect(err).NotTo(HaveOccurred())

		Eventually(stdout).Should(gbytes.Say("pid"))
		_, err = fmt.Sscanf(string(stdout.Contents()), "pid = %d\n", &pid)
		Expect(err).ToNot(HaveOccurred())

		signaller = &container_daemon.ProcessSignaller{
			Logger: lagertest.NewTestLogger("test"),
		}
	})

	Context("when a process with the given pid exists", func() {
		It("sends the signal to the process", func() {
			Expect(signaller.Signal(pid, syscall.SIGTERM)).To(Succeed())
			Eventually(stdout, "5s").Should(gbytes.Say("TERMed"))
		})
	})

	Context("when a process with the given pid does not exist", func() {
예제 #8
0
				Expect(url).To(Equal(server.URL + "/v1.2.3/right_st-" + runtime.GOOS + "-" + runtime.GOARCH + "." + ext))
				Expect(version).To(Equal(&Version{1, 2, 3}))
			})

			It("Returns an error for a nonexistent major version", func() {
				url, version, err := UpdateGetDownloadUrl(0)
				Expect(err).To(MatchError("Major version not available: 0"))
				Expect(url).To(BeEmpty())
				Expect(version).To(BeNil())
			})
		})

		Describe("Update check", func() {
			It("Outputs nothing for a dev version", func() {
				UpdateCheck("right_st dev - JUNK JUNK JUNK", buffer)
				Expect(buffer.Contents()).To(BeEmpty())
			})

			It("Outputs nothing if there is no update", func() {
				UpdateCheck("right_st v3.4.5 - JUNK JUNK JUNK", buffer)
				Expect(buffer.Contents()).To(BeEmpty())
			})

			It("Outputs that there is a new version", func() {
				UpdateCheck("right_st v3.0.0 - JUNK JUNK JUNK", buffer)
				Expect(buffer.Contents()).To(BeEquivalentTo(`There is a new v3 version of right_st (v3.4.5), to upgrade run:
    right_st update apply

See https://github.com/rightscale/right_st/blob/master/ChangeLog.md or
https://github.com/rightscale/right_st/releases for more information.
`))
예제 #9
0
				Expect(err).To(HaveOccurred())
				Expect(err).To(MatchError(&yaml.TypeError{
					Errors: []string{
						"line 4: no such field 'Some Bogus Field' in struct 'main.RightScriptMetadata'",
					},
				}))
			})
		})
	})

	Describe("Write RightScript metadata", func() {
		Context("With empty metadata", func() {
			It("should write a metadata comment", func() {
				n, err := emptyMetadata.WriteTo(buffer)
				Expect(err).To(Succeed())
				Expect(buffer.Contents()).To(BeEquivalentTo(emptyMetadataScript))
				Expect(n).To(BeEquivalentTo(66))
			})
		})
		Context("With populated metadata", func() {
			It("should write a metadata comment", func() {
				n, err := populatedMetadata.WriteTo(buffer)
				Expect(err).To(Succeed())
				Expect(buffer.Contents()).To(BeEquivalentTo(populatedMetadataScript))
				Expect(n).To(BeEquivalentTo(637))
			})
		})
		Context("With a different comment string for metadata", func() {
			It("should write a metadata comment", func() {
				n, err := differentCommentMetadata.WriteTo(buffer)
				Expect(err).To(Succeed())
예제 #10
0
파일: render_test.go 프로젝트: aemengo/fly
		})

		It("prints its payload", func() {
			Expect(out).To(gbytes.Say("hello"))
		})
	})

	Context("when an Error event is received", func() {
		BeforeEach(func() {
			receivedEvents <- event.Error{
				Message: "oh no!",
			}
		})

		It("prints its message with a red background in white, followed by a linebreak", func() {
			Expect(out.Contents()).To(ContainSubstring(ui.ErroredColor.SprintFunc()("oh no!") + "\n"))
		})
	})

	Context("when an InitializeTask event is received", func() {
		BeforeEach(func() {
			receivedEvents <- event.InitializeTask{
				TaskConfig: event.TaskConfig{
					Image: "some-image",
					Run: event.TaskRunConfig{
						Path: "/some/script",
						Args: []string{"arg1", "arg2"},
					},
				},
			}
		})
예제 #11
0
			Ω(Event{
				ID:    "some-id",
				Name:  "some-name",
				Data:  []byte("some-data"),
				Retry: 123 * time.Millisecond,
			}.Encode()).Should(Equal("id: some-id\nevent: some-name\nretry: 123\ndata: some-data\n\n"))
		})
	})

	Describe("Write", func() {
		var destination *gbytes.Buffer

		BeforeEach(func() {
			destination = gbytes.NewBuffer()
		})

		It("writes the encoded event to the destination", func() {
			event := Event{
				ID:   "some-id",
				Name: "some-name",
				Data: []byte("some-data\nsome-more-data\n"),
			}

			err := event.Write(destination)
			Ω(err).ShouldNot(HaveOccurred())

			Ω(destination.Contents()).Should(Equal([]byte(event.Encode())))
		})
	})
})
예제 #12
0
파일: help_test.go 프로젝트: Reejoshi/cli
	})

	It("shows help for all commands", func() {
		dummyTemplate := `
{{range .Commands}}{{range .CommandSubGroups}}{{range .}}
{{.Name}}
{{end}}{{end}}{{end}}
`
		help.ShowHelp(buffer, dummyTemplate)

		Expect(buffer).To(gbytes.Say("login"))
		for _, metadata := range commandregistry.Commands.Metadatas() {
			if metadata.Hidden {
				continue
			}
			Expect(buffer.Contents()).To(ContainSubstring(metadata.Name))
		}
	})

	It("shows help for all installed plugin's commands", func() {
		confighelpers.PluginRepoDir = func() string {
			return filepath.Join("..", "..", "fixtures", "config", "help-plugin-test-config")
		}

		dummyTemplate := `
{{range .Commands}}{{range .CommandSubGroups}}{{range .}}
{{.Name}}
{{end}}{{end}}{{end}}
`
		help.ShowHelp(buffer, dummyTemplate)
		Expect(buffer.Contents()).To(ContainSubstring("test1_cmd2"))
					Expect(config.Save()).To(Succeed())
				})

				It("outputs the s3 bucket and region", func() {
					Expect(outputBuffer).To(test_helpers.SayLine("Droplet store:\ts3://bucket (region)"))
				})
			})
		})

		Context("when --domain is pased", func() {
			JustBeforeEach(func() {
				test_helpers.ExecuteCommandWithArgs(targetCommand, []string{"--domain"})
			})

			It("outputs just the target host", func() {
				Expect(string(outputBuffer.Contents())).To(Equal("oldtarget.com\n"))
			})

			Context("when no target is set", func() {
				BeforeEach(func() {
					config.SetTarget("")
					Expect(config.Save()).To(Succeed())
				})

				It("informs the user the target is not set", func() {
					Expect(string(outputBuffer.Contents())).To(BeEmpty())
				})
			})
		})

		Context("when initially connecting to the receptor without authentication", func() {
			Ω(err).ShouldNot(HaveOccurred())

			file, err := os.Create(fullPath)
			Ω(err).ShouldNot(HaveOccurred())
			file.Close()
		}

		Describe("finding files to upload with From param", func() {
			It("prints the deprecation warning", func() {
				request.Params.From = "foo.tgz"
				createFile("foo.tgz")

				_, err := command.Run(sourceDir, request)
				Ω(err).ShouldNot(HaveOccurred())

				Expect(stderr.Contents()).To(ContainSubstring("WARNING:"))
				Expect(stderr.Contents()).To(ContainSubstring("Parameters 'from/to' are deprecated, use 'file' instead"))
			})

			It("does not error if there is a single match", func() {
				request.Params.From = "a/(.*).tgz"
				createFile("a/file.tgz")

				_, err := command.Run(sourceDir, request)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("errors if there are no matches", func() {
				request.Params.From = "b/(.*).tgz"
				createFile("a/file1.tgz")
				createFile("a/file2.tgz")