diff options
author | Julien Dessaux | 2021-10-22 17:59:44 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-10-25 15:22:24 +0200 |
commit | ad9b9c0f7bd4d95ddc54462970d33d92bab9392c (patch) | |
tree | b8d130d728fda49c64b6e021da31afb2418b78a0 /tests/database.nim | |
parent | Initial import (diff) | |
download | short-ad9b9c0f7bd4d95ddc54462970d33d92bab9392c.tar.gz short-ad9b9c0f7bd4d95ddc54462970d33d92bab9392c.tar.bz2 short-ad9b9c0f7bd4d95ddc54462970d33d92bab9392c.zip |
Added a functionning url shortening service
Diffstat (limited to '')
-rw-r--r-- | tests/database.nim | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/database.nim b/tests/database.nim new file mode 100644 index 0000000..9e8de52 --- /dev/null +++ b/tests/database.nim @@ -0,0 +1,41 @@ +include ../src/database + +import unittest + +const someTime = initDuration(seconds=1) +let testingNow = times.now() - 60 * someTime +let later = testingNow + 30 * someTime + +suite "database": + test "url": + let db = openDatabase(":memory:") + check db.Migrate() == true + let u = ShortUrl( + Token: "token", + Title: "title", + Url: "url", + Created: testingNow, + Expires: later, + ) + db.AddUrl(u) + try: + db.AddUrl(u) + check false + except SqliteError: + discard + var u2 = db.GetUrl(u.Token) + check u2.ID == 1 + check u2.Token == "token" + check u2.Title == "title" + check u2.Url == "url" + check u2.Created - testingNow < someTime + check u2.Expires - later < someTime + db.CleanExpired() + try: + discard db.GetUrl("token") + except SqliteError: + check false + u2.Expires = testingNow + 120 * someTime + db.AddUrl(u2[]) + db.CleanExpired() + check db.GetUrl("token") != nil |