add test for log
This commit is contained in:
parent
417c20a3c2
commit
c4683b9cd8
1 changed files with 40 additions and 0 deletions
40
sshpiperd/log_test.go
Normal file
40
sshpiperd/log_test.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateLogger(t *testing.T) {
|
||||
|
||||
// flags
|
||||
{
|
||||
logger := loggerConfig{LogFlags: 2}.createLogger()
|
||||
|
||||
if logger.Flags() != 2 {
|
||||
t.Errorf("flags not set")
|
||||
}
|
||||
}
|
||||
|
||||
// file
|
||||
{
|
||||
tmpfile, err := ioutil.TempFile("", "sshpiperlog")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create tmp file %v", err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name()) // clean up
|
||||
|
||||
logger := loggerConfig{LogFile: tmpfile.Name()}.createLogger()
|
||||
|
||||
logger.Print("test123")
|
||||
|
||||
s, _ := ioutil.ReadFile(tmpfile.Name())
|
||||
|
||||
if !strings.Contains(string(s), "test123") {
|
||||
|
||||
t.Errorf("log failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue