From cd302234af2703e79d05b07ad80999022801d2d2 Mon Sep 17 00:00:00 2001 From: w1ndyb0y Date: Mon, 21 Dec 2020 11:42:36 +0800 Subject: [PATCH] create test function --- .idea/workspace.xml | 11 +++++------ cmd/test.go | 40 +++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index acfec4a..2e7b71d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,14 +1,9 @@ - + - - - - - + + + true diff --git a/cmd/test.go b/cmd/test.go index f85f5d2..26a9aa0 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -19,30 +19,36 @@ import ( "fmt" "github.com/spf13/cobra" "github.com/tarm/serial" - "os" "it2000.com.cn/tele-recv/database" + "os" ) // testCmd represents the test command var testCmd = &cobra.Command{ Use: "test", - Short: "Test Config", - Long: `Test config file. -Test serial port`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("test called") - fmt.Println("device :",device) - c := &serial.Config{Name: device, Baud: baudrate, Size: bytesize} - s, err := serial.OpenPort(c) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - fmt.Println(c , "opened") - _ = s.Close() + Short: "Test running environment", + Long: `loading config file +Test serial port +Test load sqlite database and init table`, + Run: test, +} - database.Init(dbFile, dbInit) - }, +func test(cmd *cobra.Command, args []string) { + fmt.Println("test called") + fmt.Println("device :", device) + c := &serial.Config{Name: device, Baud: baudrate, Size: bytesize} + s, err := serial.OpenPort(c) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println(c, "opened") + _ = s.Close() + + err = database.Init(dbFile, dbInit) + if err != nil { + println("create database error ", err) + } } func init() {