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)) }) It("logs error if file is not a valid yaml", func() { yparser = NewYamlParser("../fixtures/parser/bad.yml", logger, fakeModel) _, err := yparser.Parse() Ω(err).To(HaveOccurred()) Ω(logger.ContainsSubstring([]string{"Failed to decode document"})).To(Equal(true)) }) It("validate a yaml file", func() { yparser = NewYamlParser("../fixtures/parser/test.yml", logger, fakeModel) _, err := yparser.Parse() Ω(err).ToNot(HaveOccurred()) })
}) 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) data = pluginModel.PopulateModel(parsedYaml) }) It("logs error to terminal", func() { Ω(len(data)).To(Equal(1)) Ω(logger.ContainsSubstring([]string{"unexpected field", "unknown_field"})).To(Equal(true)) }) }) })
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{}) Ω(testLogger.ContainsSubstring([]string{"Error parsing repo-index", "bad yaml file"})).To(Equal(true)) Ω(resp.Body.Len()).To(Equal(0)) }) It("marshals PluginModels into json object", func() { model := []models.Plugin{ models.Plugin{ Name: "plugin1", Description: "none", Binaries: []models.Binary{ models.Binary{ Platform: "osx", Url: "asdf123", }, }, },