forked from content-services/content-sources-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomains_test.go
56 lines (47 loc) · 1.15 KB
/
domains_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package dao
import (
"sync"
"testing"
"github.com/content-services/content-sources-backend/pkg/db"
uuid2 "github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type DomainSuite struct {
*DaoSuite
}
func TestDomainSuite(t *testing.T) {
m := DaoSuite{}
r := DomainSuite{DaoSuite: &m}
suite.Run(t, &r)
}
func (ds *DomainSuite) TestCreate() {
orgId := "DomainSuiteTest"
dd := domainDaoImpl{db: ds.tx}
name, err := dd.Create(orgId)
assert.NoError(ds.T(), err)
assert.NotEmpty(ds.T(), name)
// try again
name, err = dd.Create(orgId)
assert.NoError(ds.T(), err)
assert.NotEmpty(ds.T(), name)
name, err = dd.Fetch(orgId)
assert.NoError(ds.T(), err)
assert.NotEmpty(ds.T(), name)
}
func TestConcurrentGetDomainName(t *testing.T) {
// Note, this test does not use a transaction, as it fails when multiple go routines are trying to do that
orgId := uuid2.NewString()
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
dDao := GetDomainDao(db.DB)
dName, err := dDao.FetchOrCreateDomain(orgId)
assert.NoError(t, err)
assert.NotEmpty(t, dName)
wg.Done()
}()
}
wg.Wait()
}