func TestLogMessageOutput(t *testing.T) { cloud_controller := "API" router := "RTR" uaa := "UAA" dea := "DEA" wardenContainer := "App" stdout := logmessage.LogMessage_OUT stderr := logmessage.LogMessage_ERR date := time.Now() timestamp := date.UnixNano() sourceId := "0" protoMessage := &logmessage.LogMessage{ Message: []byte("Hello World!\n\r\n\r"), AppId: proto.String("my-app-guid"), MessageType: &stdout, SourceId: &sourceId, Timestamp: ×tamp, } msg := createMessage(t, protoMessage, &cloud_controller, &stdout) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [API]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStdoutColor("OUT Hello World!")) msg = createMessage(t, protoMessage, &cloud_controller, &stderr) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [API]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStderrColor("ERR Hello World!")) sourceId = "1" msg = createMessage(t, protoMessage, &router, &stdout) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [RTR]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStdoutColor("OUT Hello World!")) msg = createMessage(t, protoMessage, &router, &stderr) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [RTR]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStderrColor("ERR Hello World!")) sourceId = "2" msg = createMessage(t, protoMessage, &uaa, &stdout) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [UAA]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStdoutColor("OUT Hello World!")) msg = createMessage(t, protoMessage, &uaa, &stderr) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [UAA]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStderrColor("ERR Hello World!")) sourceId = "3" msg = createMessage(t, protoMessage, &dea, &stdout) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [DEA]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStdoutColor("OUT Hello World!")) msg = createMessage(t, protoMessage, &dea, &stderr) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [DEA]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStderrColor("ERR Hello World!")) sourceId = "4" msg = createMessage(t, protoMessage, &wardenContainer, &stdout) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [App/4]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStdoutColor("OUT Hello World!")) msg = createMessage(t, protoMessage, &wardenContainer, &stderr) assert.Contains(t, logMessageOutput(msg), fmt.Sprintf("%s [App/4]", date.Format(TIMESTAMP_FORMAT))) assert.Contains(t, logMessageOutput(msg), terminal.LogStderrColor("ERR Hello World!")) }
date := time.Now() timestamp := date.UnixNano() sourceId := "0" protoMessage := &logmessage.LogMessage{ Message: []byte("Hello World!\n\r\n\r"), AppId: proto.String("my-app-guid"), MessageType: &stdout, SourceId: &sourceId, Timestamp: ×tamp, } msg := createMessage(protoMessage, &cloud_controller, &stdout) Expect(LogMessageOutput(msg)).To(ContainSubstring(fmt.Sprintf("%s [API]", date.Format(TIMESTAMP_FORMAT)))) Expect(LogMessageOutput(msg)).To(ContainSubstring(terminal.LogStdoutColor("OUT Hello World!"))) msg = createMessage(protoMessage, &cloud_controller, &stderr) Expect(LogMessageOutput(msg)).To(ContainSubstring(fmt.Sprintf("%s [API]", date.Format(TIMESTAMP_FORMAT)))) Expect(LogMessageOutput(msg)).To(ContainSubstring(terminal.LogStderrColor("ERR Hello World!"))) sourceId = "1" msg = createMessage(protoMessage, &router, &stdout) Expect(LogMessageOutput(msg)).To(ContainSubstring(fmt.Sprintf("%s [RTR]", date.Format(TIMESTAMP_FORMAT)))) Expect(LogMessageOutput(msg)).To(ContainSubstring(terminal.LogStdoutColor("OUT Hello World!"))) msg = createMessage(protoMessage, &router, &stderr) Expect(LogMessageOutput(msg)).To(ContainSubstring(fmt.Sprintf("%s [RTR]", date.Format(TIMESTAMP_FORMAT)))) Expect(LogMessageOutput(msg)).To(ContainSubstring(terminal.LogStderrColor("ERR Hello World!"))) sourceId = "2" msg = createMessage(protoMessage, &uaa, &stdout)