. "github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/extensions/table"
	commonMocks "github.com/opencontrol/compliance-masonry/lib/common/mocks"
	"github.com/opencontrol/compliance-masonry/tools/vcs/mocks"
	"github.com/stretchr/testify/assert"
)

var _ = Describe("Downloader", func() {
	Describe("Constructing a new VCEntrySDownloader", func() {
		It("should return a downloader of type VCSEntryDownloader", func() {
			downloader := NewVCSDownloader()
			assert.IsType(GinkgoT(), vcsEntryDownloader{}, downloader)
		})
	})
	Describe("Downloading Entry from VCS", func() {
		table.DescribeTable("DownloadRepo", func(err error) {
			remoteSource := new(commonMocks.RemoteSource)
			remoteSource.On("GetURL").Return("https://github.com/opencontrol/notarealrepo")
			remoteSource.On("GetRevision").Return("master")
			m := new(mocks.RepoManager)
			m.On("Clone", remoteSource.GetURL(), remoteSource.GetRevision(), ".").Return(err)
			v := vcsEntryDownloader{m}
			v.DownloadRepo(remoteSource, ".")
			m.AssertExpectations(GinkgoT())
		},
			table.Entry("No error returned", nil),
			table.Entry("An error returned", errors.New("an error")),
		)
	})
})
package opencontrol

import (
	. "github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/extensions/table"
	"github.com/stretchr/testify/assert"
)

var _ = Describe("Base", func() {

	Describe("Retrieving the schema version", func() {
		table.DescribeTable("GetSchemaVersion", func(b Base, expectedVersion string) {
			assert.Equal(GinkgoT(), b.GetSchemaVersion(), expectedVersion)
		},
			table.Entry("Empty / new base struct", Base{}, ""),
			table.Entry("regular base struct", Base{SchemaVersion: "1.0.0"}, "1.0.0"),
		)
	})
})
package common

import (
	"errors"
	. "github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/extensions/table"
	"github.com/opencontrol/compliance-masonry/tools/constants"
	"github.com/opencontrol/compliance-masonry/tools/vcs/mocks"
	"github.com/stretchr/testify/assert"
)

var _ = Describe("Entry", func() {
	Describe("Retrieving the config file", func() {
		table.DescribeTable("GetConfigFile", func(e Entry, expectedPath string) {
			assert.Equal(GinkgoT(), e.GetConfigFile(), expectedPath)
		},
			table.Entry("Empty / new base struct to return default", Entry{}, constants.DefaultConfigYaml),
			table.Entry("overriden config file path", Entry{Path: "samplepath"}, "samplepath"),
		)
	})
	Describe("Constructing a new VCEntrySDownloader", func() {
		It("should return a downloader of type VCSEntryDownloader", func() {
			downloader := NewVCSDownloader()
			assert.IsType(GinkgoT(), vcsEntryDownloader{}, downloader)
		})
	})
	Describe("Downloading Entry from VCS", func() {
		table.DescribeTable("DownloadEntry", func(e Entry, err error) {
			m := new(mocks.RepoManager)
			m.On("Clone", e.URL, e.Revision, ".").Return(err)
			v := vcsEntryDownloader{m}
			v.DownloadEntry(e, ".")