summaryrefslogtreecommitdiff
path: root/flow-cleaner_test.go
diff options
context:
space:
mode:
authorDaniel Langesten <daniel.langest@gmail.com>2015-03-25 15:31:12 +0100
committerDaniel Langesten <daniel.langest@gmail.com>2015-03-25 15:31:12 +0100
commit3e1f05b51d44ce8b7f6d57db7c3d5af6464d7f9b (patch)
treef7f96f802a9d9359b5c2dd32b3ba5f1d720d100a /flow-cleaner_test.go
parent42811bebad023e591c5b8fbc1122c62f77a375d9 (diff)
updated tests so you just run 'go test' and also so it tests db as well as from stdin
Diffstat (limited to 'flow-cleaner_test.go')
-rw-r--r--flow-cleaner_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/flow-cleaner_test.go b/flow-cleaner_test.go
index a8f9f55..51283a7 100644
--- a/flow-cleaner_test.go
+++ b/flow-cleaner_test.go
@@ -6,7 +6,9 @@ import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"io"
+ "io/ioutil"
"os"
+ "strings"
"testing"
"time"
)
@@ -25,9 +27,58 @@ func TestCleaningFromJSON(t *testing.T) {
DBPass: "nil",
}
+ fmt.Println("== Testing to process from stdin ==")
+ prepareDB(t, cfg)
testProcessFromStdin(t, cfg)
time.Sleep(15 * time.Second)
controlDB(t, cfg)
+ fmt.Println("== Finished testing to process from stdin ==")
+}
+
+func TestCleaningFromDB(t *testing.T) {
+ cfg := &Config{
+ Limit: 0,
+ Interval: "5min",
+ Epsilon: 0,
+ DataSource: "mysql",
+
+ DBConn: "",
+ DBName: "test",
+ RawTable: "test_raw",
+ CleanTable: "test_clean",
+ DBUser: "flowcleaner",
+ DBPass: "nil",
+ }
+
+ fmt.Println("== Testing to process from DB ==")
+ prepareDB(t, cfg)
+ processFromDB(cfg)
+ controlDB(t, cfg)
+ fmt.Println("== Finished testing to process from DB ==")
+}
+
+func prepareDB(t *testing.T, cfg *Config) {
+ db, err := sql.Open("mysql", cfg.DBUser+":"+cfg.DBPass+"@"+cfg.DBConn+"/"+cfg.DBName)
+ if err != nil {
+ t.Fatal("Failed to connect to db:", err)
+ }
+ defer db.Close()
+
+ file, err := ioutil.ReadFile("testdata/dbTestSetup.mysql")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ for _, query := range strings.Split(string(file), ";") {
+ query = strings.TrimSpace(query)
+ if len(query) > 0 {
+ _, err = db.Exec(query + ";")
+ if err != nil {
+ fmt.Println("QUERY:", query)
+ t.Fatal(err)
+ }
+ }
+ }
}
func testProcessFromStdin(t *testing.T, cfg *Config) {