示例#1
0
	var cmdExec cmd_exec_fake.FakeCmdExec

	BeforeEach(func() {
		cmdExec = cmd_exec_fake.NewCmdExec()
		p = NewParser(cmdExec, "TestApp", "0", false, false)
	})
	Describe("Test getFailedDownloads()", func() {
		It("Should return empty []string because no directory string downloads have failed.", func() {
			fails := p.GetFailedDownloads()
			Ω(len(fails)).To(Equal(0))
		})
	})

	Describe("Test ExecParseDir()", func() {
		It("Should return 8 files and 3 directories", func() {
			cmdExec.SetOutput("Getting files for app smithInTheHouse in org jstart / space evans as [email protected]...\nOK\n\n.npmignore 136B\nLICENSE 1.1K\nREADME.md 5.3K\nReadme_zh-cn.md 28.4K\nbin/ -\ncomponent.json 282B\nindex.js 95B\njade-language.md 20.0K\njade.js 757.2K\njade.md 11.3K\nlib/ -\nnode_modules/ -\npackage.json 2.0K\nruntime.js 5.1K")
			files, directories := p.ExecParseDir("readPath")
			Ω(len(files)).To(Equal(11))
			Ω(files[0]).To(Equal(".npmignore"))
			Ω(files[1]).To(Equal("LICENSE"))
			Ω(files[2]).To(Equal("README.md"))
			Ω(files[3]).To(Equal("Readme_zh-cn.md"))
			Ω(files[4]).To(Equal("component.json"))
			Ω(files[5]).To(Equal("index.js"))
			Ω(files[6]).To(Equal("jade-language.md"))
			Ω(files[7]).To(Equal("jade.js"))
			Ω(files[8]).To(Equal("jade.md"))
			Ω(files[9]).To(Equal("package.json"))
			Ω(files[10]).To(Equal("runtime.js"))
			Ω(len(directories)).To(Equal(3))
			Ω(directories[0]).To(Equal("bin/"))
示例#2
0
		currentDirectory string
	)

	currentDirectory, _ = os.Getwd()
	os.MkdirAll(currentDirectory+"/testFiles/", 0755)

	cmdExec = cmd_exec_fake.NewCmdExec()
	d = NewDownloader(cmdExec, &wg, "appName", "0", "rootWorkingDirectory", false, false)

	// downloadfile also tests the following functions
	// WriteFile(), CheckDownload()
	Describe("Test DownloadFile function", func() {
		Context("download and create a file containing only 'helloWorld'", func() {
			It("create test1.txt", func() {
				writePath := currentDirectory + "/testFiles/test1.txt"
				cmdExec.SetOutput("Getting files for app payToWin in org jstart / space koldus as [email protected]...\nOK\nHello World")
				wg.Add(1)
				go d.DownloadFile("", writePath, &wg)
				wg.Wait()

				fileContents, err := ioutil.ReadFile(writePath)
				Ω(err).To(BeNil())
				Ω(string(fileContents)).To(Equal("Hello World"))
				writePath = currentDirectory + "/testFiles/test2.txt"
				cmdExec.SetOutput("Getting files for app payToWin in org jstart / space koldus as [email protected]...\nOK\nLorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content. It's also called placeholder (or filler) text. It's a convenient tool for mock-ups. It helps to outline the visual elements of a document or presentation, eg typography, font, or layout. Lorem ipsum is mostly a part of a Latin text by the classical author and philosopher Cicero. Its words and letters have been changed by addition or removal, so to deliberately render its content nonsensical; it's not genuine, correct, or comprehensible Latin anymore. While lorem ipsum's still resembles classical Latin, it actually has no meaning whatsoever. As Cicero's text doesn't contain the letters K, W, or Z, alien to latin, these, and others are often inserted randomly to mimic the typographic appearence of European languages, as are digraphs not to be found in the original.")
				wg.Add(1)
				go d.DownloadFile("", writePath, &wg)
				wg.Wait()

				fileInfo, err := os.Stat(writePath)
				Ω(err).To(BeNil())