コード例 #1
0
					Path: "",
				},
			}
			getter := VCSAndLocalFSGetter{}
			worker := new(common.ConfigWorker)
			downloader := new(mocks.EntryDownloader)
			downloader.On("DownloadEntry", entries[0], mock.AnythingOfType("string")).Return(downloadEntryError)
			worker.Downloader = downloader
			fsUtil := new(fsmocks.Util)
			fsUtil.On("TempDir", "", "opencontrol-resources").Return("sometempdir", tempDirError)
			data := []byte("schema_version: 1.0.0")
			fsUtil.On("OpenAndReadFile", mock.AnythingOfType("string")).Return(data, openAndReadFileError)
			parser := new(mocks.SchemaParser)
			schema := new(mocks.BaseSchema)
			schema.On("GetResources", mock.AnythingOfType("string"), mock.AnythingOfType("string"), worker).Return(getResourcesError)
			parser.On("ParseV1_0_0", data).Return(schema, parseV1_0_0Error)
			worker.Parser = parser
			worker.FSUtil = fsUtil
			err := getter.GetRemoteResources("dest", "subfolder", worker, entries)
			assert.Equal(GinkgoT(), expectedError, err)

		},
			Entry("success", nil, nil, nil, nil, nil, nil),
			Entry("fail to get resources", nil, nil, nil, errors.New("error getting resources"), nil, errors.New("error getting resources")),
			Entry("fail to parse config", nil, nil, nil, nil, errors.New("error parsing"), errors.New("error parsing")),
			Entry("fail to open and read file", nil, nil, errors.New("error reading file"), nil, nil, errors.New("error reading file")),
			Entry("fail to download repo", errors.New("error downloading entry"), nil, nil, nil, nil, errors.New("error downloading entry")),
			Entry("fail to create temp dir", nil, errors.New("error creating tempdir"), nil, nil, nil, errors.New("error creating tempdir")),
		)
	})
})
コード例 #2
0
			schema, err = Parse(parser, []byte(`schema_version: "0.0.0"`))
			assert.Equal(GinkgoT(), err, ErrUnknownSchemaVersion)
		})
	})
	Describe("ParseV1_0_0 scenarios", func() {
		var (
			data          []byte
			expectedError error
			mockSchema    *mocks.BaseSchema
		)
		BeforeEach(func() {
			expectedError = nil
			mockSchema = new(mocks.BaseSchema)
		})
		JustBeforeEach(func() {
			parser.On("ParseV1_0_0", data).Return(mockSchema, expectedError)
		})
		Context("when the ParseV1_0_0 will not be called", func() {
			It("should not call it when passing in 1.0", func() {
				Parse(parser, []byte(`schema_version: "1.0"`))
				parser.AssertNotCalled(GinkgoT(), "ParseV1_0_0", data)
			})
		})
		Context("when the ParseV1_0_0 will is called", func() {
			BeforeEach(func() {
				data = []byte(`schema_version: "1.0.0"`)
			})
			Context("when ParseV1_0_0 is passed valid data", func() {
				It("should call ParseV1_0_0", func() {
					_, err = Parse(parser, data)
					parser.AssertCalled(GinkgoT(), "ParseV1_0_0", data)