create test function

This commit is contained in:
w1ndyb0y
2020-12-21 11:42:36 +08:00
parent 8e417699c0
commit cd302234af
2 changed files with 28 additions and 23 deletions
+5 -6
View File
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ab419b68-984b-4661-bb9a-26bcba1547b3" name="Default Changelist" comment=""> <list default="true" id="ab419b68-984b-4661-bb9a-26bcba1547b3" name="Default Changelist" comment="create test function">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/root.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/root.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/test.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/test.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/cmd/test.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/sqlite.go" beforeDir="false" afterPath="$PROJECT_DIR$/database/sqlite.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/telegram.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/telegram.yaml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -56,6 +51,10 @@
</map> </map>
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration">
<MESSAGE value="create test function" />
<option name="LAST_COMMIT_MESSAGE" value="create test function" />
</component>
<component name="VgoProject"> <component name="VgoProject">
<integration-enabled>true</integration-enabled> <integration-enabled>true</integration-enabled>
<environment> <environment>
+13 -7
View File
@@ -19,17 +19,21 @@ import (
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tarm/serial" "github.com/tarm/serial"
"os"
"it2000.com.cn/tele-recv/database" "it2000.com.cn/tele-recv/database"
"os"
) )
// testCmd represents the test command // testCmd represents the test command
var testCmd = &cobra.Command{ var testCmd = &cobra.Command{
Use: "test", Use: "test",
Short: "Test Config", Short: "Test running environment",
Long: `Test config file. Long: `loading config file
Test serial port`, Test serial port
Run: func(cmd *cobra.Command, args []string) { Test load sqlite database and init table`,
Run: test,
}
func test(cmd *cobra.Command, args []string) {
fmt.Println("test called") fmt.Println("test called")
fmt.Println("device :", device) fmt.Println("device :", device)
c := &serial.Config{Name: device, Baud: baudrate, Size: bytesize} c := &serial.Config{Name: device, Baud: baudrate, Size: bytesize}
@@ -41,8 +45,10 @@ Test serial port`,
fmt.Println(c, "opened") fmt.Println(c, "opened")
_ = s.Close() _ = s.Close()
database.Init(dbFile, dbInit) err = database.Init(dbFile, dbInit)
}, if err != nil {
println("create database error ", err)
}
} }
func init() { func init() {