aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2021-12-03 07:19:28 -0700
committerJordan <me@jordan.im>2021-12-03 07:19:28 -0700
commitb0835fc63877c63e88e75840c5d52d3167ad5e10 (patch)
tree9db697711cab98fa9c49f87d40d6f7212baae19c /db_test.go
downloadkeep-b0835fc63877c63e88e75840c5d52d3167ad5e10.tar.gz
keep-b0835fc63877c63e88e75840c5d52d3167ad5e10.zip
initial commit
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/db_test.go b/db_test.go
new file mode 100644
index 0000000..b429aaf
--- /dev/null
+++ b/db_test.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "database/sql"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "testing"
+)
+
+var (
+ db *sql.DB
+ db_path string
+)
+
+func TestInitDB(t *testing.T) {
+
+ tmpDB, _ := ioutil.TempFile("", "tmp-*.db")
+ db_path = tmpDB.Name()
+ os.Remove(db_path)
+ db = initDB(db_path)
+}
+
+func TestAddArchived(t *testing.T) {
+
+ m := Message{
+ URL: "http://example.com/",
+ Author: "000000000000000000",
+ Guild: "000000000000000000",
+ Channel: "000000000000000000",
+ }
+ addArchived(db, &m, 200)
+}
+
+func TestIsCached(t *testing.T) {
+
+ url := "http://example.com/"
+ cached, status_code := isCached(db, url)
+ if status_code != http.StatusOK || cached != true {
+ t.Errorf("Received %t, %d; wanted %t, %d", cached, status_code, true,
+ http.StatusOK)
+ }
+}
+
+func TestDBCleanup(t *testing.T) {
+
+ os.Remove(db_path)
+}