💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › cd2686de4f1e5498c8a07720f3… captured on 2023-09-08 at 16:27:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-05-24)

🚧 View Differences

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

Go Back

0 package db

1

2 import (

3 "testing"

4 "gemigit/test"

5 )

6

7 const invalidRepoName = "$repo"

8 const validRepoName = "repo"

9

10 func TestCreateRepo(t *testing.T) {

11

12 initDB(t)

13

14 user, signature := createUserAndSession(t)

15

16 test.IsNotNil(t, user.CreateRepo(invalidRepoName, signature),

17 "name should be invalid")

18 test.IsNil(t, user.CreateRepo(validRepoName, signature))

19 test.IsNotNil(t, user.CreateRepo(validRepoName, signature),

20 "repository name should be already taken")

21 test.IsNotNil(t, user.CreateRepo(validRepoName + "a", "invalid"),

22 "signature should be invalid")

23 }

24

25 func TestGetRepoID(t *testing.T) {

26

27 initDB(t)

28

29 user, signature := createUserAndSession(t)

30

31 test.IsNil(t, user.CreateRepo(validRepoName, signature))

32 _, err := GetRepoID(validRepoName, user.ID)

33 test.IsNil(t, err)

34 _, err = GetRepoID(validRepoName + "a", user.ID)

35 test.IsNotNil(t, err, "should return repository not found")

36 _, err = GetRepoID(validRepoName, user.ID + 1)

37 test.IsNotNil(t, err, "should return user not found")

38

39 }

40

41 func TestChangeRepoName(t *testing.T) {

42

43 initDB(t)

44

45 user, signature := createUserAndSession(t)

46

47 test.IsNil(t, user.CreateRepo(validRepoName, signature))

48

49 err := user.ChangeRepoName(validRepoName, invalidRepoName,

50 signature)

51 test.IsNotNil(t, err, "repo name should be invalid")

52

53 err = user.ChangeRepoName(validRepoName, validRepoName + "a",

54 signature + "a")

55 test.IsNotNil(t, err, "signature should be invalid")

56

57 err = user.ChangeRepoName(validRepoName + "a", validRepoName,

58 signature)

59 test.IsNotNil(t, err, "repository should be invalid")

60

61 id, err := GetRepoID(validRepoName, user.ID)

62 test.IsNil(t, err)

63

64 test.IsNil(t, user.ChangeRepoName(validRepoName, validRepoName + "a",

65 signature))

66

67 _, err = GetRepoID(validRepoName, user.ID);

68 test.IsNotNil(t, err, "should return repository not found")

69

70 id_alt, err := GetRepoID(validRepoName + "a", user.ID)

71 test.IsNil(t, err)

72

73 test.IsEqual(t, id_alt, id)

74 }

75

76 func TestChangeRepoDesc(t *testing.T) {

77

78 initDB(t)

79

80 user, signature := createUserAndSession(t)

81 description := test.FuncName(t)

82

83 test.IsNil(t, user.CreateRepo(validRepoName, signature))

84

85 test.IsNotNil(t, user.ChangeRepoDesc(validRepoName + "a", description),

86 "repo name should be invalid")

87

88 test.IsNil(t, user.ChangeRepoDesc(validRepoName, description))

89

90 repo, err := user.GetRepo(validRepoName)

91 test.IsNil(t, err)

92 test.IsEqual(t, repo.Description, description)

93

94 }

95

96 func TestGetRepoDesc(t *testing.T) {

97

98 initDB(t)

99

100 user, signature := createUserAndSession(t)

101 description := test.FuncName(t)

102

103 _, err := GetRepoDesc(validRepoName, user.Name)

104 test.IsNotNil(t, err, "repository should be invalid")

105 test.IsNil(t, user.CreateRepo(validRepoName, signature))

106 test.IsNil(t, user.ChangeRepoDesc(validRepoName, description))

107

108 desc, err := GetRepoDesc(validRepoName, user.Name)

109 test.IsNil(t, err)

110 test.IsEqual(t, desc, description)

111 }

112

113 func TestDeleteRepo(t *testing.T) {

114

115 initDB(t)

116

117 user, signature := createUserAndSession(t)

118 test.IsNil(t, user.CreateRepo(validRepoName, signature))

119 test.IsNotNil(t, user.DeleteRepo(validRepoName, signature + "a"),

120 "signature should be invalid")

121 test.IsNotNil(t, user.DeleteRepo(validRepoName + "a", signature),

122 "repository should be invalid")

123 test.IsNil(t, user.DeleteRepo(validRepoName, signature))

124 _, err := user.GetRepo(validRepoName)

125 test.IsNotNil(t, err, "repository should be invalid")

126 }

127

128 func TestIsRepoPublic(t *testing.T) {

129

130 initDB(t)

131

132 user, signature := createUserAndSession(t)

133

134 test.IsNil(t, user.CreateRepo(validRepoName, signature))

135

136 _, err := IsRepoPublic(validRepoName + "a", user.Name)

137 test.IsNotNil(t, err, "repository should be invalid")

138

139 b, err := IsRepoPublic(validRepoName, user.Name)

140 test.IsNil(t, err)

141 test.IsEqual(t, b, false)

142

143 test.IsNotNil(t, user.TogglePublic(validRepoName, signature + "a"),

144 "signature should be invalid")

145

146 test.IsNotNil(t, user.TogglePublic(validRepoName + "a", signature),

147 "repository should be invalid")

148

149 test.IsNil(t, user.TogglePublic(validRepoName, signature))

150

151 b, err = IsRepoPublic(validRepoName, user.Name)

152 test.IsNil(t, err)

153 test.IsEqual(t, b, true)

154

155 test.IsNil(t, user.TogglePublic(validRepoName, signature))

156

157 b, err = IsRepoPublic(validRepoName, user.Name)

158 test.IsNil(t, err)

159 test.IsEqual(t, b, false)

160 }

161

162 func TestGetPublicRepo(t *testing.T) {

163

164 initDB(t)

165

166 user, signature := createUserAndSession(t)

167

168 test.IsNil(t, user.CreateRepo(validRepoName, signature))

169 test.IsNil(t, user.CreateRepo(validRepoName + "a", signature))

170

171 repos, err := GetPublicRepo()

172 test.IsNil(t, err)

173 test.IsEqual(t, len(repos), 0)

174

175 test.IsNil(t, user.TogglePublic(validRepoName, signature))

176

177 repos, err = GetPublicRepo()

178 test.IsNil(t, err)

179 test.IsEqual(t, len(repos), 1)

180

181 test.IsNil(t, user.TogglePublic(validRepoName + "a", signature))

182

183 repos, err = GetPublicRepo()

184 test.IsNil(t, err)

185 test.IsEqual(t, len(repos), 2)

186

187 }

188

189 func TestGetRepos(t *testing.T) {

190

191 initDB(t)

192

193 user, signature := createUserAndSession(t)

194

195 test.IsNil(t, user.CreateRepo(validRepoName, signature))

196 test.IsNil(t, user.CreateRepo(validRepoName + "a", signature))

197 test.IsNil(t, user.TogglePublic(validRepoName, signature))

198

199 repos, err := user.GetRepos(false)

200 test.IsNil(t, err)

201 test.IsEqual(t, len(repos), 2)

202

203 repos, err = user.GetRepos(true)

204 test.IsNil(t, err)

205 test.IsEqual(t, len(repos), 1)

206 }

207