Skip to content

Commit 9e6a79b

Browse files
upgrade to use testfixtures v3 (#11904)
* upgrade to use testfixtures v3 * simplify logic * make vendor * update per @lunny * Update templates/repo/empty.tmpl * Update templates/repo/empty.tmpl Co-authored-by: Lauris BH <[email protected]>
1 parent 1645d4a commit 9e6a79b

File tree

97 files changed

+8813
-5463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+8813
-5463
lines changed

contrib/pr/checkout.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/go-git/go-git/v5/plumbing"
3838
context2 "github.com/gorilla/context"
3939
"github.com/unknwon/com"
40-
"gopkg.in/testfixtures.v2"
4140
"xorm.io/xorm"
4241
)
4342

@@ -96,14 +95,12 @@ func runPR() {
9695
setting.Database.LogSQL = true
9796
//x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
9897

99-
var helper testfixtures.Helper = &testfixtures.SQLite{}
10098
models.NewEngine(context.Background(), func(_ *xorm.Engine) error {
10199
return nil
102100
})
103101
models.HasEngine = true
104102
//x.ShowSQL(true)
105103
err = models.InitFixtures(
106-
helper,
107104
path.Join(curDir, "models/fixtures/"),
108105
)
109106
if err != nil {

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ require (
4444
github.com/go-redis/redis v6.15.2+incompatible
4545
github.com/go-sql-driver/mysql v1.4.1
4646
github.com/go-swagger/go-swagger v0.21.0
47+
github.com/go-testfixtures/testfixtures/v3 v3.2.0
4748
github.com/gobwas/glob v0.2.3
4849
github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28
4950
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14
@@ -56,7 +57,6 @@ require (
5657
github.com/issue9/identicon v1.0.1
5758
github.com/jaytaylor/html2text v0.0.0-20160923191438-8fb95d837f7d
5859
github.com/jmhodges/levigo v1.0.0 // indirect
59-
github.com/joho/godotenv v1.3.0 // indirect
6060
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657
6161
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
6262
github.com/klauspost/compress v1.10.2
@@ -66,8 +66,7 @@ require (
6666
github.com/mailru/easyjson v0.7.0 // indirect
6767
github.com/markbates/goth v1.61.2
6868
github.com/mattn/go-isatty v0.0.11
69-
github.com/mattn/go-oci8 v0.0.0-20190320171441-14ba190cf52d // indirect
70-
github.com/mattn/go-sqlite3 v1.11.0
69+
github.com/mattn/go-sqlite3 v2.0.2+incompatible
7170
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75
7271
github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81
7372
github.com/mgechev/revive v1.0.2
@@ -115,8 +114,7 @@ require (
115114
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
116115
gopkg.in/ini.v1 v1.52.0
117116
gopkg.in/ldap.v3 v3.0.2
118-
gopkg.in/testfixtures.v2 v2.5.0
119-
gopkg.in/yaml.v2 v2.2.8
117+
gopkg.in/yaml.v2 v2.3.0
120118
mvdan.cc/xurls/v2 v2.1.0
121119
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
122120
xorm.io/builder v0.3.7

go.sum

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
149149
github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
150150
github.com/denisenkom/go-mssqldb v0.0.0-20190924004331-208c0a498538 h1:bpWCJ5MddHsv4Xtl3azkK89mZzd/vvut32mvAnKbyUA=
151151
github.com/denisenkom/go-mssqldb v0.0.0-20190924004331-208c0a498538/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
152+
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
152153
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzqk8QCaRC4os14xoKDdbHqqlJtJA0oc1ZAjg=
153154
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
154155
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
@@ -278,6 +279,8 @@ github.com/go-swagger/go-swagger v0.21.0 h1:AX9mdfzp6eJtUe92nFrWmbK7ocRgkCDPJs0F
278279
github.com/go-swagger/go-swagger v0.21.0/go.mod h1:tDb8PdDVFcaE8EPXkMOsuxpL3UEPiwu1UDZar9Z/1RY=
279280
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0=
280281
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0=
282+
github.com/go-testfixtures/testfixtures/v3 v3.2.0 h1:FGAW3z5UzmrZGjR/dZp1u3Tbld0SDmirLO4RrR5++7Q=
283+
github.com/go-testfixtures/testfixtures/v3 v3.2.0/go.mod h1:RZctY24ixituGC73XlAV1gkCwYMVwiSwPm26MNlQIhE=
281284
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y=
282285
github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM=
283286
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
@@ -437,6 +440,7 @@ github.com/lestrrat-go/jwx v0.9.0/go.mod h1:iEoxlYfZjvoGpuWwxUz+eR5e6KTJGsaRcy/Y
437440
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
438441
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
439442
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
443+
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
440444
github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY=
441445
github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
442446
github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:uNwtsDp7ci48vBTTxDuwcoTXz4lwtDTe7TjCQ0noaWY=
@@ -462,13 +466,13 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
462466
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
463467
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
464468
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
465-
github.com/mattn/go-oci8 v0.0.0-20190320171441-14ba190cf52d h1:m+dSK37rFf2fqppZhg15yI2IwC9BtucBiRwSDm9VL8g=
466-
github.com/mattn/go-oci8 v0.0.0-20190320171441-14ba190cf52d/go.mod h1:/M9VLO+lUPmxvoOK2PfWRZ8mTtB4q1Hy9lEGijv9Nr8=
467469
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
468470
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
469471
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
470472
github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q=
471473
github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
474+
github.com/mattn/go-sqlite3 v2.0.2+incompatible h1:qzw9c2GNT8UFrgWNDhCTqRqYUSmu/Dav/9Z58LGpk7U=
475+
github.com/mattn/go-sqlite3 v2.0.2+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
472476
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
473477
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
474478
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 h1:Pijfgr7ZuvX7QIQiEwLdRVr3RoMG+i0SbBO1Qu+7yVk=
@@ -610,6 +614,8 @@ github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmq
610614
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
611615
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
612616
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
617+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
618+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
613619
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
614620
github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
615621
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
@@ -890,8 +896,6 @@ gopkg.in/ldap.v3 v3.0.2 h1:R6RBtabK6e1GO0eQKtkyOFbAHO73QesLzI2w2DZ6b9w=
890896
gopkg.in/ldap.v3 v3.0.2/go.mod h1:oxD7NyBuxchC+SgJDE1Q5Od05eGt29SDQVBmV+HYbzw=
891897
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
892898
gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
893-
gopkg.in/testfixtures.v2 v2.5.0 h1:N08B7l2GzFQenyYbzqthDnKAA+cmb17iAZhhFxr7JHw=
894-
gopkg.in/testfixtures.v2 v2.5.0/go.mod h1:vyAq+MYCgNpR29qitQdLZhdbLFf4mR/2MFJRFoQZZ2M=
895899
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
896900
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
897901
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
@@ -902,8 +906,11 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
902906
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
903907
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
904908
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
909+
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
905910
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
906911
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
912+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
913+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
907914
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
908915
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
909916
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

integrations/integration_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/PuerkitoBio/goquery"
3737
"github.com/stretchr/testify/assert"
3838
"github.com/unknwon/com"
39-
"gopkg.in/testfixtures.v2"
4039
)
4140

4241
var mac *macaron.Macaron
@@ -88,22 +87,7 @@ func TestMain(m *testing.M) {
8887
}
8988
}
9089

91-
var helper testfixtures.Helper
92-
if setting.Database.UseMySQL {
93-
helper = &testfixtures.MySQL{}
94-
} else if setting.Database.UsePostgreSQL {
95-
helper = &testfixtures.PostgreSQL{}
96-
} else if setting.Database.UseSQLite3 {
97-
helper = &testfixtures.SQLite{}
98-
} else if setting.Database.UseMSSQL {
99-
helper = &testfixtures.SQLServer{}
100-
} else {
101-
fmt.Println("Unsupported RDBMS for integration tests")
102-
os.Exit(1)
103-
}
104-
10590
err := models.InitFixtures(
106-
helper,
10791
path.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
10892
)
10993
if err != nil {

models/test_fixtures.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,48 @@ package models
66

77
import (
88
"fmt"
9+
"os"
910
"time"
1011

11-
"gopkg.in/testfixtures.v2"
12+
"github.com/go-testfixtures/testfixtures/v3"
1213
"xorm.io/xorm/schemas"
1314
)
1415

15-
var fixtures *testfixtures.Context
16+
var fixtures *testfixtures.Loader
1617

1718
// InitFixtures initialize test fixtures for a test database
18-
func InitFixtures(helper testfixtures.Helper, dir string) (err error) {
19-
testfixtures.SkipDatabaseNameCheck(true)
20-
fixtures, err = testfixtures.NewFolder(x.DB().DB, helper, dir)
19+
func InitFixtures(dir string) (err error) {
20+
testfiles := testfixtures.Directory(dir)
21+
dialect := "unknown"
22+
switch x.Dialect().URI().DBType {
23+
case schemas.POSTGRES:
24+
dialect = "postgres"
25+
case schemas.MYSQL:
26+
dialect = "mysql"
27+
case schemas.MSSQL:
28+
dialect = "mssql"
29+
case schemas.SQLITE:
30+
dialect = "sqlite3"
31+
default:
32+
fmt.Println("Unsupported RDBMS for integration tests")
33+
os.Exit(1)
34+
}
35+
loaderOptions := []func(loader *testfixtures.Loader) error{
36+
testfixtures.Database(x.DB().DB),
37+
testfixtures.Dialect(dialect),
38+
testfixtures.DangerousSkipTestDatabaseCheck(),
39+
testfiles,
40+
}
41+
42+
if x.Dialect().URI().DBType == schemas.POSTGRES {
43+
loaderOptions = append(loaderOptions, testfixtures.SkipResetSequences())
44+
}
45+
46+
fixtures, err = testfixtures.New(loaderOptions...)
47+
if err != nil {
48+
return err
49+
}
50+
2151
return err
2252
}
2353

models/unit_tests.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/stretchr/testify/assert"
2121
"github.com/unknwon/com"
22-
"gopkg.in/testfixtures.v2"
2322
"xorm.io/xorm"
2423
"xorm.io/xorm/names"
2524
)
@@ -101,7 +100,7 @@ func CreateTestEngine(fixturesDir string) error {
101100
x.ShowSQL(true)
102101
}
103102

104-
return InitFixtures(&testfixtures.SQLite{}, fixturesDir)
103+
return InitFixtures(fixturesDir)
105104
}
106105

107106
func removeAllWithRetry(dir string) error {

vendor/gopkg.in/testfixtures.v2/.gitignore renamed to vendor/github.com/go-testfixtures/testfixtures/v3/.gitignore

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-testfixtures/testfixtures/v3/.goreleaser.yml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/gopkg.in/testfixtures.v2/.sample.env renamed to vendor/github.com/go-testfixtures/testfixtures/v3/.sample.env

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-testfixtures/testfixtures/v3/CHANGELOG.md

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-testfixtures/testfixtures/v3/Dockerfile

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)