mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-26 17:49:15 +01:00
add unit test for GetLocalLog
This commit is contained in:
@@ -2,9 +2,11 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crawlab/config"
|
"crawlab/config"
|
||||||
|
"fmt"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,3 +22,29 @@ func TestDeleteLogPeriodically(t *testing.T) {
|
|||||||
DeleteLogPeriodically()
|
DeleteLogPeriodically()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetLocalLog(t *testing.T) {
|
||||||
|
//create a log file for test
|
||||||
|
logPath := "../logs/crawlab/test.log"
|
||||||
|
f, err := os.Create(logPath)
|
||||||
|
defer f.Close()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_, err = f.Write([]byte("This is for test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
Convey("Test GetLocalLog", t, func() {
|
||||||
|
Convey("Test response", func() {
|
||||||
|
logStr, err := GetLocalLog(logPath)
|
||||||
|
log.Info(string(logStr))
|
||||||
|
fmt.Println(err)
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
//delete the test log file
|
||||||
|
os.Remove(logPath)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user