-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mohamed Mahmoud <[email protected]>
- Loading branch information
1 parent
7f947b6
commit e0951d8
Showing
5 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
err := os.MkdirAll("./output/flow", 0700) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func TestInitFlowDB(t *testing.T) { | ||
db := initFlowDB("test") | ||
if db == nil { | ||
t.Error("Expected database to initialize successfully") | ||
} | ||
defer os.RemoveAll("./output") | ||
err := createFlowsDBTable(db) | ||
if err != nil { | ||
t.Error("Unexpected error creating flows table") | ||
} | ||
|
||
// Test success case | ||
// {"Bytes":32} | ||
bs := []byte{123, 34, 66, 121, 116, 101, 115, 34, 58, 51, 50, 125} | ||
err = insertFlowToDB(db, bs) | ||
if err != nil { | ||
t.Errorf("Unexpected error inserting flow: %v", err) | ||
} | ||
|
||
q, err := queryDB(db, "SELECT Bytes FROM flow") | ||
if err != nil { | ||
t.Error("Unexpected error querying flow") | ||
} | ||
if len(q) != 1 { | ||
t.Error("Expected 1 row in flow table") | ||
} | ||
|
||
if q[0] != "32" { | ||
t.Error("Unexpected result from query") | ||
} | ||
|
||
// Test DB error case | ||
db.Close() | ||
err = insertFlowToDB(db, []byte("1")) | ||
if err == nil { | ||
t.Error("Expected error for closed DB") | ||
} | ||
} |
File renamed without changes.
File renamed without changes.