💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › 92eabdea07b4bf289fcfc6eca1… captured on 2023-11-14 at 08:18:43. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-09-08)

-=-=-=-=-=-=-

Go Back

0 package db

1

2 import (

3 "testing"

4 "os"

5 "gemigit/test"

6 )

7

8 const validPassword = "pa$w0rd"

9 const invalidPassword = "pass"

10 const invalidUsername = "0user"

11

12 var initialized bool

13 func initDB(t *testing.T) {

14

15 if initialized {

16 return

17 }

18

19 test.IsNil(t, Init("sqlite3", "test.db", false))

20

21 _, err := db.Exec("DELETE FROM token;")

22 test.IsNil(t, err)

23 _, err = db.Exec("DELETE FROM user;")

24 test.IsNil(t, err)

25 _, err = db.Exec("DELETE FROM repo;")

26 test.IsNil(t, err)

27 _, err = db.Exec("DELETE FROM member;")

28 test.IsNil(t, err)

29 _, err = db.Exec("DELETE FROM groups;")

30 test.IsNil(t, err)

31 _, err = db.Exec("DELETE FROM certificate;")

32 test.IsNil(t, err)

33 _, err = db.Exec("DELETE FROM access;")

34 test.IsNil(t, err)

35

36 UpdateTable()

37 initialized = true

38

39 }

40

41 func TestDB(t *testing.T) {

42

43 initDB(t)

44 test.IsNil(t, Close())

45 test.IsNotNil(t, Init("sqlite3", "/invalid/test.db", false),

46 "should be unable to create database")

47 test.IsNotNil(t, Init("invalid", "test.db", false),

48 "should be unable to open database")

49 os.Remove("test.db")

50 test.IsNil(t, Init("sqlite3", "test.db", false))

51 test.IsNil(t, Close())

52 initialized = false

53 }

54

55 func TestUpdateTable(t *testing.T) {

56

57 initDB(t)

58

59 _, err := db.Exec("ALTER TABLE user DROP COLUMN description;")

60 test.IsNil(t, err)

61

62 username := test.FuncName(t)

63 test.IsNil(t, Register(username, validPassword))

64

65 UpdateTable()

66 }

67