2019-03-04 14:33:48 +00:00
|
|
|
package exportlogs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExportLogs(t *testing.T) {
|
|
|
|
tempf, err := ioutil.TempFile("", "test-dump-logs")
|
|
|
|
require.NoError(t, err)
|
|
|
|
logs := "first line\nsecond line\n"
|
2019-10-04 15:21:24 +00:00
|
|
|
n, err := fmt.Fprint(tempf, logs)
|
2019-03-04 14:33:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(logs), n)
|
|
|
|
response := ExportFromBaseFile(tempf.Name())
|
|
|
|
require.Empty(t, response.Error)
|
|
|
|
require.Len(t, response.Logs, 1)
|
|
|
|
log := response.Logs[0]
|
|
|
|
require.Equal(t, false, log.Compressed)
|
|
|
|
require.Equal(t, tempf.Name(), log.Filename)
|
2019-05-06 16:08:47 +00:00
|
|
|
require.Equal(t, logs, log.Content)
|
2019-03-04 14:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExportLogsNoFileError(t *testing.T) {
|
|
|
|
response := ExportFromBaseFile("doesnt-exist")
|
|
|
|
require.Equal(t, "error reading file doesnt-exist: open doesnt-exist: no such file or directory", response.Error)
|
|
|
|
}
|