/
testing.go
55 lines (48 loc) · 1.46 KB
/
testing.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
package client
import (
"context"
"fmt"
"os"
"testing"
"time"
"github.com/cloudquery/plugin-sdk/plugins"
"github.com/cloudquery/plugin-sdk/schema"
"github.com/cloudquery/plugin-sdk/specs"
"github.com/golang/mock/gomock"
"github.com/rs/zerolog"
)
type TestOptions struct{}
func AwsMockTestHelper(t *testing.T, table *schema.Table, builder func(*testing.T, *gomock.Controller) Services, _ TestOptions) {
version := "vDev"
table.IgnoreInTests = false
t.Helper()
ctrl := gomock.NewController(t)
l := zerolog.New(zerolog.NewTestWriter(t)).Output(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMicro},
).Level(zerolog.DebugLevel).With().Timestamp().Logger()
newTestExecutionClient := func(ctx context.Context, logger zerolog.Logger, spec specs.Source) (schema.ClientMeta, error) {
var awsSpec Spec
if err := spec.UnmarshalSpec(&awsSpec); err != nil {
return nil, fmt.Errorf("failed to unmarshal aws spec: %w", err)
}
c := NewAwsClient(l)
c.ServicesManager.InitServicesForPartitionAccountAndRegion("aws", "testAccount", "us-east-1", builder(t, ctrl))
c.Partition = "aws"
return &c, nil
}
p := plugins.NewSourcePlugin(
table.Name,
version,
[]*schema.Table{
table,
},
newTestExecutionClient)
p.SetLogger(l)
plugins.TestSourcePluginSync(t, p, specs.Source{
Name: "dev",
Path: "cloudquery/dev",
Version: version,
Tables: []string{table.Name},
Destinations: []string{"mock-destination"},
})
}