コード例 #1
0
		DescribeTable("", func(downloadEntryError, tempDirError, openAndReadFileError, getResourcesError, parseV1_0_0Error, expectedError error) {
			entries := []common.Entry{
				{
					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
package config_test

import (
	. "github.com/opencontrol/compliance-masonry/config"

	. "github.com/onsi/ginkgo"
	"github.com/opencontrol/compliance-masonry/config/common"
	"github.com/opencontrol/compliance-masonry/config/common/mocks"
	"github.com/stretchr/testify/assert"
	"github.com/vektra/errors"
)

var _ = Describe("Parse", func() {
	var (
		parser *mocks.SchemaParser
		err    error
		schema common.BaseSchema
	)

	BeforeEach(func() {
		parser = new(mocks.SchemaParser)
	})

	Describe("bad input scenarios", func() {
		It("should detect there's no data to parse when given nil data", func() {
			schema, err = Parse(parser, nil)
			assert.Equal(GinkgoT(), ErrNoDataToParse, err)
		})
		It("should detect there's no data to parse when given empty data", func() {
			schema, err = Parse(parser, []byte(""))
			assert.Equal(GinkgoT(), ErrNoDataToParse, err)