package parser_test

import (
	"github.com/cloudfoundry-incubator/cli-plugin-repo/models/fakes"
	. "github.com/cloudfoundry-incubator/cli-plugin-repo/parser"
	"github.com/cloudfoundry-incubator/cli-plugin-repo/test_helpers"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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

	var (
		yparser   YamlParser
		logger    *test_helpers.TestLogger
		fakeModel *fakes.FakePluginModel
	)

	BeforeEach(func() {
		logger = test_helpers.NewTestLogger()
		fakeModel = &fakes.FakePluginModel{}
	})

	Describe("Parse()", func() {

		It("logs error if file does not exist", func() {
			yparser = NewYamlParser("../path/to/nowhere/bad.yml", logger, fakeModel)
			_, err := yparser.Parse()
			Ω(err).To(HaveOccurred())
			Ω(logger.ContainsSubstring([]string{"File does not exist"})).To(Equal(true))
Beispiel #2
0
			Ω(data[0].Binaries[0].Platform).To(Equal("osx"))
			Ω(data[1].Name).To(Equal("test2"))
			Ω(data[1].Binaries[1].Platform).To(Equal("linux32"))
		})

		It("turns optional string fields with nil value into empty string", func() {
			Ω(len(data)).To(Equal(2))
			Ω(data[0].Authors[0].Name).To(Equal("sample_name"))
			Ω(data[0].Company).To(Equal(""))
			Ω(data[0].Homepage).To(Equal(""))
		})
	})

	Context("When raw data contains unknown field", func() {
		var (
			logger *test_helpers.TestLogger
		)

		BeforeEach(func() {
			parsedYaml = map[interface{}]interface{}{
				"plugins": []interface{}{
					map[interface{}]interface{}{
						"name":          "test1",
						"description":   "n/a",
						"unknown_field": "123",
					},
				},
			}

			logger = test_helpers.NewTestLogger()
			pluginModel = NewPlugins(logger)
	"github.com/cloudfoundry-incubator/cli-plugin-repo/models"
	"github.com/cloudfoundry-incubator/cli-plugin-repo/parser/fakes"
	"github.com/cloudfoundry-incubator/cli-plugin-repo/test_helpers"

	. "github.com/cloudfoundry-incubator/cli-plugin-repo/server"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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

	var (
		fakeParser *fakes.FakeYamlParser
		testLogger *test_helpers.TestLogger
		resp       *httptest.ResponseRecorder
	)

	BeforeEach(func() {
		fakeParser = &fakes.FakeYamlParser{}
		testLogger = test_helpers.NewTestLogger()
		resp = httptest.NewRecorder()
	})

	Describe("ListPlugins()", func() {
		It("logs any error returns by the parser, and returns empty body", func() {
			fakeParser.ParseReturns([]models.Plugin{}, errors.New("bad yaml file"))
			h := NewServerHandles(fakeParser, testLogger)
			h.ListPlugins(resp, &http.Request{})