summary refs log tree commit diff stats
path: root/svc/db_test.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-09 02:58:45 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-09 02:58:45 -0400
commite10fc64f9855262c4a9511025dffcc1d603c7206 (patch)
tree75cd201bdb02c2d3a077b07a128a93b3322b8bd3 /svc/db_test.go
parente280417e804cb0f3723639b14a7af12e6bdebd09 (diff)
downloadgetwtxt-e10fc64f9855262c4a9511025dffcc1d603c7206.tar.gz
using sync.Once for DB init in tests, cleaned up test config init
Diffstat (limited to 'svc/db_test.go')
-rw-r--r--svc/db_test.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/svc/db_test.go b/svc/db_test.go
index 8cd0b61..abf7626 100644
--- a/svc/db_test.go
+++ b/svc/db_test.go
@@ -9,16 +9,20 @@ import (
 
 func Test_pushpullDatabase(t *testing.T) {
 	initTestConf()
-	initDatabase()
+	initTestDB()
+
 	out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt")
 	if err != nil {
 		t.Errorf("Couldn't set up test: %v\n", err)
 	}
+
 	statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt")
 	if err != nil {
 		t.Errorf("Couldn't set up test: %v\n", err)
 	}
+
 	twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", "", net.ParseIP("127.0.0.1"), statusmap)
+
 	remoteRegistries.Mu.Lock()
 	remoteRegistries.List = append(remoteRegistries.List, "https://twtxt.tilde.institute/api/plain/users")
 	remoteRegistries.Mu.Unlock()
@@ -39,6 +43,7 @@ func Test_pushpullDatabase(t *testing.T) {
 
 	t.Run("Pulling from Database", func(t *testing.T) {
 		pullDB()
+
 		twtxtCache.Mu.RLock()
 		if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok {
 			t.Errorf("Missing user previously pushed to database\n")
@@ -49,10 +54,7 @@ func Test_pushpullDatabase(t *testing.T) {
 }
 func Benchmark_pushDatabase(b *testing.B) {
 	initTestConf()
-
-	if len(dbChan) < 1 {
-		initDatabase()
-	}
+	initTestDB()
 
 	if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok {
 		out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt")
@@ -79,10 +81,8 @@ func Benchmark_pushDatabase(b *testing.B) {
 }
 func Benchmark_pullDatabase(b *testing.B) {
 	initTestConf()
-
-	if len(dbChan) < 1 {
-		initDatabase()
-	}
+	initTestDB()
+	b.ResetTimer()
 
 	for i := 0; i < b.N; i++ {
 		pullDB()