Skip to content

Commit 48f953a

Browse files
authored
fix(tests): Parallel plugin testing, remove old faker (#292)
Something like cloudquery/cloudquery#2788 but in the sdk.
1 parent a65f081 commit 48f953a

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.19
44

55
require (
66
github.com/bradleyjkemp/cupaloy/v2 v2.8.0
7-
github.com/cloudquery/faker/v3 v3.7.7
87
github.com/getsentry/sentry-go v0.13.0
98
github.com/ghodss/yaml v1.0.0
109
github.com/gofrs/uuid v4.3.0+incompatible
@@ -14,6 +13,7 @@ require (
1413
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2
1514
github.com/modern-go/reflect2 v1.0.2
1615
github.com/rs/zerolog v1.28.0
16+
github.com/schollz/progressbar/v3 v3.11.0
1717
github.com/spf13/cast v1.5.0
1818
github.com/spf13/cobra v1.5.0
1919
github.com/stretchr/testify v1.8.0
@@ -38,7 +38,6 @@ require (
3838
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
3939
github.com/pmezard/go-difflib v1.0.0 // indirect
4040
github.com/rivo/uniseg v0.4.2 // indirect
41-
github.com/schollz/progressbar/v3 v3.11.0 // indirect
4241
github.com/spf13/pflag v1.0.5 // indirect
4342
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
4443
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
33
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
44
github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
55
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
6-
github.com/cloudquery/faker/v3 v3.7.7 h1:vODOmAXGhxAacVrUOjr4Jti2lFhXgkPjG6/L3C2REgQ=
7-
github.com/cloudquery/faker/v3 v3.7.7/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
86
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
97
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
108
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@@ -146,8 +144,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
146144
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
147145
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
148146
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
149-
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
150-
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
151147
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
152148
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
153149
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

plugins/source_testing.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"testing"
77

8-
"github.com/cloudquery/faker/v3"
98
"github.com/cloudquery/plugin-sdk/schema"
109
"github.com/cloudquery/plugin-sdk/specs"
1110
"github.com/rs/zerolog"
@@ -21,14 +20,19 @@ type ResourceTestCase struct {
2120
SkipIgnoreInTest bool
2221
}
2322

24-
func init() {
25-
_ = faker.SetRandomMapAndSliceMinSize(1)
26-
_ = faker.SetRandomMapAndSliceMaxSize(1)
27-
}
28-
29-
func TestSourcePluginSync(t *testing.T, plugin *SourcePlugin, logger zerolog.Logger, spec specs.Source) {
23+
func TestSourcePluginSync(t *testing.T, plugin *SourcePlugin, logger zerolog.Logger, spec specs.Source, opts ...TestSourcePluginOption) {
3024
t.Helper()
3125

26+
o := &testSourcePluginOptions{
27+
parallel: true,
28+
}
29+
for _, opt := range opts {
30+
opt(o)
31+
}
32+
if o.parallel {
33+
t.Parallel()
34+
}
35+
3236
resourcesChannel := make(chan *schema.Resource)
3337
var fetchErr error
3438

@@ -46,6 +50,18 @@ func TestSourcePluginSync(t *testing.T, plugin *SourcePlugin, logger zerolog.Log
4650
validateTables(t, plugin.Tables(), syncedResources)
4751
}
4852

53+
type TestSourcePluginOption func(*testSourcePluginOptions)
54+
55+
func WithTestSourcePluginNoParallel() TestSourcePluginOption {
56+
return func(f *testSourcePluginOptions) {
57+
f.parallel = false
58+
}
59+
}
60+
61+
type testSourcePluginOptions struct {
62+
parallel bool
63+
}
64+
4965
func getTableResources(t *testing.T, table *schema.Table, resources []*schema.Resource) []*schema.Resource {
5066
t.Helper()
5167

schema/column_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/cloudquery/faker/v3"
1312
"github.com/google/uuid"
1413
"github.com/stretchr/testify/assert"
1514
"github.com/thoas/go-funk"
@@ -109,26 +108,30 @@ var validateFixtures = []validateFixture{
109108
}
110109

111110
func GenerateMac() net.HardwareAddr {
112-
mac, _ := net.ParseMAC(faker.MacAddress())
113-
return mac
111+
hw, err := net.ParseMAC(`00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01`)
112+
if err != nil {
113+
panic(err)
114+
}
115+
return hw
114116
}
115117
func GenerateMacPtr() *net.HardwareAddr {
116-
mac, _ := net.ParseMAC(faker.MacAddress())
117-
return &mac
118+
r := GenerateMac()
119+
return &r
118120
}
119121

120122
func GenerateIPv4Ptr() *net.IP {
121-
ip := net.ParseIP(faker.IPv4())
122-
return &ip
123+
r := net.ParseIP("127.0.0.1")
124+
return &r
123125
}
124126

125127
func GenerateIPv6Ptr() *net.IP {
126-
ip := net.ParseIP(faker.IPv6())
127-
return &ip
128+
r := net.ParseIP("2001:db8::68")
129+
return &r
128130
}
129131

130132
func GenerateCIDR() *net.IPNet {
131-
_, mask, _ := net.ParseCIDR(fmt.Sprintf("%s/%d", faker.IPv4(), rand.Int31n(16)+16))
133+
ip := GenerateIPv4Ptr()
134+
_, mask, _ := net.ParseCIDR(fmt.Sprintf("%s/%d", ip.String(), rand.Int31n(16)+16))
132135
return mask
133136
}
134137

0 commit comments

Comments
 (0)