Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unit tets for no-prefix writer
  • Loading branch information
mRrvz committed Feb 2, 2021
commit 9d8d5ee20329ed97ebb4933ed6dc3501380b72fc
43 changes: 43 additions & 0 deletions cli/running/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func getLogsBytes(logs []string) []byte {
return []byte(strings.Join(logs, "\n"))
}

func getLogsNoPrefix(logs []string) string {
resLines := make([]string, len(logs))
for i := range logs {
resLines[i] = fmt.Sprintf("%s", logs[i])
}

return strings.Join(resLines, "\n")
}

func getLogsWithPrefix(prefix string, logs []string) string {
resLines := make([]string, len(logs))
for i := range logs {
Expand Down Expand Up @@ -62,3 +71,37 @@ func TestWrite(t *testing.T) {
assert.Equal(len(logBytes), n)
assert.Equal(getLogsWithPrefix(id, logs), out.String())
}

func TestNoPrefixWrite(t *testing.T) {
t.Parallel()

assert := assert.New(t)
out := bytes.NewBuffer(nil)

writer := newDummyWriter()
writer.out = out

out.Reset()
logs := []string{
"Line_01",
"Multiline02!",
"Log.Line03",
}

logBytes := getLogsBytes(logs)
n, err := writer.Write(logBytes)
assert.Nil(err)
assert.Equal(len(logBytes), n)
assert.Equal(getLogsNoPrefix(logs), out.String())

out.Reset()
logs = []string{
"One line log without prefix.",
}

logBytes = getLogsBytes(logs)
n, err = writer.Write(logBytes)
assert.Nil(err)
assert.Equal(len(logBytes), n)
assert.Equal(getLogsNoPrefix(logs), out.String())
}