Files
crawlab/backend/services/log_test.go
yaziming ee808e0e60 refactor(all): refactor code
remove redundant code and some code refactor
2019-10-11 16:01:57 +08:00

42 lines
809 B
Go

package services
import (
"crawlab/config"
"crawlab/utils"
"fmt"
"github.com/apex/log"
. "github.com/smartystreets/goconvey/convey"
"github.com/spf13/viper"
"os"
"testing"
)
func TestDeleteLogPeriodically(t *testing.T) {
Convey("Test DeleteLogPeriodically", t, func() {
err := config.InitConfig("../conf/config.yml")
So(err, ShouldBeNil)
log.Info("初始化配置成功")
logDir := viper.GetString("log.path")
log.Info(logDir)
DeleteLogPeriodically()
})
}
func TestGetLocalLog(t *testing.T) {
//create a log file for test
logPath := "../logs/crawlab/test.log"
f, err := os.Create(logPath)
defer utils.Close(f)
if err != nil {
fmt.Println(err)
} else {
_, err = f.WriteString("This is for test")
fmt.Println(err)
}
//delete the test log file
_ = os.Remove(logPath)
}