/
testsuite.go
64 lines (52 loc) · 1.65 KB
/
testsuite.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
57
58
59
60
61
62
63
64
package testcontext
import (
"crypto/tls"
"log"
"net/http"
"os"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"time"
"github.com/cucumber/godog"
"github.com/kyma-project/api-gateway/tests/integration/pkg/client"
"github.com/kyma-project/api-gateway/tests/integration/pkg/helpers"
"github.com/kyma-project/api-gateway/tests/integration/pkg/resource"
"github.com/spf13/pflag"
"github.com/vrischmann/envconfig"
"k8s.io/client-go/dynamic"
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
type Testsuite interface {
Name() string
FeaturePath() []string
InitScenarios(ctx *godog.ScenarioContext)
Setup() error
TearDown()
ResourceManager() *resource.Manager
K8sClient() dynamic.Interface
BeforeSuiteHooks() []func() error
AfterSuiteHooks() []func() error
}
type TestsuiteFactory func(httpClient *helpers.RetryableHttpClient, k8sClient dynamic.Interface, rm *resource.Manager, config Config) Testsuite
func New(config Config, factory TestsuiteFactory) (Testsuite, error) {
pflag.Parse()
if err := envconfig.Init(&config); err != nil {
log.Fatalf("Unable to setup config: %v", err)
}
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: time.Second * 10,
}
retryingHttpClient := helpers.NewClientWithRetry(httpClient, GetRetryOpts())
k8sClient, err := client.GetDynamicClient()
if err != nil {
return nil, err
}
logf.SetLogger(zap.New(zap.WriteTo(os.Stdout), zap.UseDevMode(true)))
rm := resource.NewManager(GetRetryOpts())
ctx := factory(retryingHttpClient, k8sClient, rm, config)
err = ctx.Setup()
return ctx, err
}