Skip to content

Commit

Permalink
test: refactor e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i committed Nov 4, 2024
1 parent 12be5b8 commit 271ab63
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 513 deletions.
9 changes: 7 additions & 2 deletions pkg/testutil/spec_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func CreateMinimalYtsaurusResource(namespace string) *ytv1.Ytsaurus {
}
}

func CreateBaseYtsaurusResource(namespace string) *ytv1.Ytsaurus {
ytsaurus := CreateMinimalYtsaurusResource(namespace)
func WithBaseYtsaurusComponents(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
ytsaurus = WithBootstrap(ytsaurus)
ytsaurus = WithScheduler(ytsaurus)
ytsaurus = WithControllerAgents(ytsaurus)
Expand All @@ -121,6 +120,12 @@ func CreateBaseYtsaurusResource(namespace string) *ytv1.Ytsaurus {
return ytsaurus
}

func CreateBaseYtsaurusResource(namespace string) *ytv1.Ytsaurus {
ytsaurus := CreateMinimalYtsaurusResource(namespace)
ytsaurus = WithBaseYtsaurusComponents(ytsaurus)
return ytsaurus
}

// TODO (l0kix2): merge with ytconfig build spec helpers.
func WithDataNodes(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
return WithDataNodesCount(ytsaurus, 3, nil)
Expand Down
39 changes: 31 additions & 8 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import (
"k8s.io/utils/ptr"

. "github.com/onsi/ginkgo/v2"
gtypes "github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
otypes "github.com/onsi/gomega/types"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"

clientgoscheme "k8s.io/client-go/kubernetes/scheme"
clientgoretry "k8s.io/client-go/util/retry"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand Down Expand Up @@ -106,6 +108,14 @@ var _ = SynchronizedBeforeSuite(func(ctx context.Context) []byte {
Expect(k8sClient).NotTo(BeNil())
})

func ShouldPreserveArtifacts() bool {
suiteConfig, _ := GinkgoConfiguration()
if !suiteConfig.FailFast {
return false
}
return CurrentSpecReport().State.Is(gtypes.SpecStateFailed | gtypes.SpecStateTimedout)
}

var _ = BeforeEach(func() {
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(context.TODO())
Expand Down Expand Up @@ -181,21 +191,34 @@ func NewYtsaurusStatusTracker() func(*ytv1.Ytsaurus) bool {
}
}

func ExpectYtsaurus(ctx context.Context, name types.NamespacedName) Assertion {
var ytsaurus ytv1.Ytsaurus
Expect(k8sClient.Get(ctx, name, &ytsaurus)).Should(Succeed())
func UpdateYtsaurus(ctx context.Context, ytsaurus *ytv1.Ytsaurus) {
var current ytv1.Ytsaurus
name := client.ObjectKeyFromObject(ytsaurus)
err := clientgoretry.RetryOnConflict(clientgoretry.DefaultRetry, func() error {
Expect(k8sClient.Get(ctx, name, &current)).To(Succeed())
// Fetch current resource version: any status update changes it too.
ytsaurus.SetResourceVersion(current.GetResourceVersion())
return k8sClient.Update(ctx, ytsaurus)
})
Expect(err).ToNot(HaveOccurred())
}

func CheckYtsaurus(ctx context.Context, ytsaurus *ytv1.Ytsaurus) Assertion {
name := client.ObjectKeyFromObject(ytsaurus)
err := k8sClient.Get(ctx, name, ytsaurus)
Expect(err).ToNot(HaveOccurred())
return Expect(ytsaurus)
}

func EventuallyYtsaurus(ctx context.Context, name types.NamespacedName, timeout time.Duration) AsyncAssertion {
var ytsaurus ytv1.Ytsaurus
func EventuallyYtsaurus(ctx context.Context, ytsaurus *ytv1.Ytsaurus, timeout time.Duration) AsyncAssertion {
trackStatus := NewYtsaurusStatusTracker()
name := client.ObjectKeyFromObject(ytsaurus)
return Eventually(ctx, func(ctx context.Context) (*ytv1.Ytsaurus, error) {
err := k8sClient.Get(ctx, name, &ytsaurus)
err := k8sClient.Get(ctx, name, ytsaurus)
if err == nil {
trackStatus(&ytsaurus)
trackStatus(ytsaurus)
}
return &ytsaurus, err
return ytsaurus, err
}, timeout, pollInterval)
}

Expand Down
Loading

0 comments on commit 271ab63

Please sign in to comment.