forked from noobaa/noobaa-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admission_suite_integ_test.go
49 lines (40 loc) · 1.1 KB
/
admission_suite_integ_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
package admissionintegtests
import (
"context"
"log"
"os"
"testing"
"time"
"github.com/noobaa/noobaa-operator/v5/pkg/util"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes"
)
var clientset *kubernetes.Clientset
var logger *log.Logger
func TestAdmission(t *testing.T) {
// this variable is defined in .github/workflows/run_admission_test.yml
// indication of running in integration test environment
_, ok := os.LookupEnv("OPERATOR_IMAGE")
if !ok {
t.Skip() // Not an integration test, skip
}
RegisterFailHandler(Fail)
RunSpecs(t, "Admission Suite")
}
func connectToK8s() (*kubernetes.Clientset, error) {
clientset, err := kubernetes.NewForConfig(util.KubeConfig())
if err != nil {
logger.Printf("failed to create K8s clientset")
return nil, err
}
return clientset, nil
}
var _ = BeforeSuite(func(ctx context.Context) {
By("Connecting to K8S cluster")
logger = log.New(GinkgoWriter, "INFO: ", log.Lshortfile)
var err error
clientset, err = connectToK8s()
Expect(err).ToNot(HaveOccurred())
Expect(clientset).ToNot(BeNil())
}, NodeTimeout(60*time.Second))