go-log/internal_logger_alert_test.go

71 lines
1.2 KiB
Go
Raw Normal View History

2021-02-09 20:51:40 +00:00
package flog
import (
"bytes"
"testing"
)
func TestInternalLogger_Alertf(t *testing.T) {
tests := []struct{
Format string
Array []interface{}
Expected string
}{
{
Format: "",
Array: []interface{}(nil),
Expected: "[ALERT] \n",
},
{
Format: "",
Array: []interface{}{},
Expected: "[ALERT] \n",
},
{
Format: "hello world",
Array: []interface{}(nil),
Expected: "[ALERT] hello world\n",
},
{
Format: "hello world",
Array: []interface{}{},
Expected: "[ALERT] hello world\n",
},
{
Format: "hello %s",
Array: []interface{}{"Joe"},
Expected: "[ALERT] hello Joe\n",
},
{
Format: "hello %s %s",
Array: []interface{}{"Joe", "Blow"},
Expected: "[ALERT] hello Joe Blow\n",
},
}
for testNumber, test := range tests {
var buffer bytes.Buffer
logger := NewLogger(&buffer)
logger.Alertf(test.Format, test.Array...)
if expected, actual := test.Expected, buffer.String(); expected != actual {
t.Errorf("For tst #%d, the actual result is not what was expected.", testNumber)
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
t.Logf("ACTUAL: %s", actual)
continue
}
}
}