From b0835fc63877c63e88e75840c5d52d3167ad5e10 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 3 Dec 2021 07:19:28 -0700 Subject: initial commit --- db_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 db_test.go (limited to 'db_test.go') 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) +} -- cgit v1.2.3-54-g00ecf