func (matcher *SliceMatcher) Match(actual interface{}) (success bool, err error) { actualStrings, ok := actual.([]string) if !ok { return false, nil } allStringsMatched := make([]bool, len(matcher.expected)) for index, expectedArray := range matcher.expected { for _, actualValue := range actualStrings { allStringsFound := true for _, expectedValue := range expectedArray { allStringsFound = allStringsFound && strings.Contains(terminal.Decolorize(actualValue), expectedValue) } if allStringsFound { allStringsMatched[index] = true break } } } for index, value := range allStringsMatched { if !value { matcher.failedAtIndex = index return false, nil } } return true, nil }
createMessage := func(sourceId string, sourceName string, msgType logmessage.LogMessage_MessageType, date time.Time) *logmessage.LogMessage { timestamp := date.UnixNano() return &logmessage.LogMessage{ Message: []byte("Hello World!\n\r\n\r"), AppId: proto.String("my-app-guid"), MessageType: &msgType, SourceId: &sourceId, Timestamp: ×tamp, SourceName: &sourceName, } } Context("when the message comes from an app", func() { It("includes the instance index", func() { msg := createMessage("4", "App", logmessage.LogMessage_OUT, date) Expect(terminal.Decolorize(LogMessageOutput(msg, time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [App/4] OUT Hello World!")) }) }) Context("when the message comes from a cloudfoundry component", func() { It("doesn't include the instance index", func() { msg := createMessage("4", "DEA", logmessage.LogMessage_OUT, date) Expect(terminal.Decolorize(LogMessageOutput(msg, time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA] OUT Hello World!")) }) }) Context("when the message was written to stderr", func() { It("shows the log type as 'ERR'", func() { msg := createMessage("4", "DEA", logmessage.LogMessage_ERR, date) Expect(terminal.Decolorize(LogMessageOutput(msg, time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA] ERR Hello World!")) })