Skip to content

Commit

Permalink
refactor: extract test conditions into generic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
osmman committed Oct 24, 2024
1 parent ca2114a commit 554c12b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 106 deletions.
27 changes: 27 additions & 0 deletions test/e2e/support/condition/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package condition

import (
"context"
"github.com/onsi/gomega"
"github.com/securesign/operator/internal/apis"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"k8s.io/apimachinery/pkg/api/meta"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func IsReady(f apis.ConditionsAwareObject) bool {
if f == nil {
return false
}
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}

func DeploymentIsRunning(ctx context.Context, cli client.Client, namespace, component string) func(g gomega.Gomega) (bool, error) {
return func(g gomega.Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppPartOf: constants.AppName,
constants.LabelAppComponent: component,
})
}
}
19 changes: 6 additions & 13 deletions test/e2e/support/tas/ctlog/ctlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@ package ctlog

import (
"context"

"github.com/securesign/operator/test/e2e/support"
"github.com/securesign/operator/test/e2e/support/condition"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/ctlog/actions"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.CTlog) bool {
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}, BeTrue()))
WithTransform(condition.IsReady, BeTrue()))

Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.ComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.ComponentName)).
Should(BeTrue())
}

func GetServerPod(ctx context.Context, cli client.Client, ns string) func() *v1.Pod {
Expand All @@ -44,10 +37,10 @@ func GetServerPod(ctx context.Context, cli client.Client, ns string) func() *v1.
func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.CTlog {
return func() *v1alpha1.CTlog {
instance := &v1alpha1.CTlog{}
Expect(cli.Get(ctx, types.NamespacedName{
_ = cli.Get(ctx, types.NamespacedName{
Namespace: ns,
Name: name,
}, instance)).To(Succeed())
}, instance)
return instance
}
}
Expand Down
19 changes: 6 additions & 13 deletions test/e2e/support/tas/fulcio/fulcio.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@ package fulcio

import (
"context"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/fulcio/actions"
"github.com/securesign/operator/test/e2e/support"
"github.com/securesign/operator/test/e2e/support/condition"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.Fulcio) bool {
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}, BeTrue()))
WithTransform(condition.IsReady, BeTrue()))

Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.ComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.ComponentName)).
Should(BeTrue())
}

func GetServerPod(ctx context.Context, cli client.Client, ns string) func() *v1.Pod {
Expand All @@ -43,10 +36,10 @@ func GetServerPod(ctx context.Context, cli client.Client, ns string) func() *v1.
func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.Fulcio {
return func() *v1alpha1.Fulcio {
instance := &v1alpha1.Fulcio{}
Expect(cli.Get(ctx, types.NamespacedName{
_ = cli.Get(ctx, types.NamespacedName{
Namespace: ns,
Name: name,
}, instance)).To(Succeed())
}, instance)
return instance
}
}
Expand Down
26 changes: 8 additions & 18 deletions test/e2e/support/tas/rekor/rekor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,30 @@ package rekor

import (
"context"

"github.com/securesign/operator/test/e2e/support"
"github.com/securesign/operator/test/e2e/support/condition"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/rekor/actions"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.Rekor) bool {
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}, BeTrue()))
WithTransform(condition.IsReady, BeTrue()))

// server
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.ServerComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.ServerComponentName)).
Should(BeTrue())

// redis
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.RedisComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.RedisComponentName)).
Should(BeTrue())
}

func GetServerPod(ctx context.Context, cli client.Client, ns string) func() *v1.Pod {
Expand All @@ -52,10 +42,10 @@ func GetServerPod(ctx context.Context, cli client.Client, ns string) func() *v1.
func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.Rekor {
return func() *v1alpha1.Rekor {
instance := &v1alpha1.Rekor{}
Expect(cli.Get(ctx, types.NamespacedName{
_ = cli.Get(ctx, types.NamespacedName{
Namespace: ns,
Name: name,
}, instance)).To(Succeed())
}, instance)
return instance
}
}
Expand Down
11 changes: 3 additions & 8 deletions test/e2e/support/tas/rekor/search_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ package rekor

import (
"context"

"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/test/e2e/support/condition"

. "github.com/onsi/gomega"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/rekor/actions"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func VerifySearchUI(ctx context.Context, cli client.Client, namespace string) {
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.UIComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.UIComponentName)).
Should(BeTrue())
}
12 changes: 4 additions & 8 deletions test/e2e/support/tas/securesign/securesign.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ package securesign

import (
"context"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/constants"
"k8s.io/apimachinery/pkg/api/meta"
"github.com/securesign/operator/test/e2e/support/condition"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.Securesign) bool {
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}, BeTrue()))
WithTransform(condition.IsReady, BeTrue()))
}

func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.Securesign {
return func() *v1alpha1.Securesign {
instance := &v1alpha1.Securesign{}
Expect(cli.Get(ctx, types.NamespacedName{
_ = cli.Get(ctx, types.NamespacedName{
Namespace: ns,
Name: name,
}, instance)).To(Succeed())
}, instance)
return instance
}
}
30 changes: 8 additions & 22 deletions test/e2e/support/tas/trillian/trillian.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,31 @@ package trillian

import (
"context"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/trillian/actions"
"k8s.io/apimachinery/pkg/api/meta"
"github.com/securesign/operator/test/e2e/support/condition"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string, dbPresent bool) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.Trillian) bool {
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}, BeTrue()))
WithTransform(condition.IsReady, BeTrue()))

if dbPresent {
// trillian-db
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.DbComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.DbComponentName)).
Should(BeTrue())
}

// log server
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.LogServerComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.LogServerComponentName)).
Should(BeTrue())

// log signer
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.LogSignerComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.LogSignerComponentName)).
Should(BeTrue())
}

func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.Trillian {
Expand Down
18 changes: 6 additions & 12 deletions test/e2e/support/tas/tsa/tsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,33 @@ import (

tsaUtils "github.com/securesign/operator/internal/controller/tsa/utils"
"github.com/securesign/operator/test/e2e/support"
"github.com/securesign/operator/test/e2e/support/condition"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/constants"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.TimestampAuthority) bool {
return meta.IsStatusConditionTrue(f.GetConditions(), constants.Ready)
}, BeTrue()))
WithTransform(condition.IsReady, BeTrue()))

// server
Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: "timestamp-authority",
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, "timestamp-authority")).
Should(BeTrue())
}

func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.TimestampAuthority {
return func() *v1alpha1.TimestampAuthority {
instance := &v1alpha1.TimestampAuthority{}
Expect(cli.Get(ctx, types.NamespacedName{
_ = cli.Get(ctx, types.NamespacedName{
Namespace: ns,
Name: name,
}, instance)).To(Succeed())
}, instance)
return instance
}
}
Expand Down
18 changes: 6 additions & 12 deletions test/e2e/support/tas/tuf/tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,40 @@ package tuf

import (
"context"
"github.com/securesign/operator/test/e2e/support/condition"
"strings"
"time"

. "github.com/onsi/gomega"
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/controller/annotations"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes"
"github.com/securesign/operator/internal/controller/common/utils/kubernetes/job"
"github.com/securesign/operator/internal/controller/constants"
"github.com/securesign/operator/internal/controller/tuf/actions"
utils2 "github.com/securesign/operator/internal/controller/tuf/utils"
appsv1 "k8s.io/api/apps/v1"
v12 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func Verify(ctx context.Context, cli client.Client, namespace string, name string) {
Eventually(Get(ctx, cli, namespace, name)).Should(
WithTransform(func(f *v1alpha1.Tuf) string {
return meta.FindStatusCondition(f.GetConditions(), constants.Ready).Reason
}, Equal(constants.Ready)))
WithTransform(condition.IsReady, BeTrue()))

Eventually(func(g Gomega) (bool, error) {
return kubernetes.DeploymentIsRunning(ctx, cli, namespace, map[string]string{
constants.LabelAppComponent: actions.ComponentName,
})
}).Should(BeTrue())
Eventually(condition.DeploymentIsRunning(ctx, cli, namespace, actions.ComponentName)).
Should(BeTrue())
}

func Get(ctx context.Context, cli client.Client, ns string, name string) func() *v1alpha1.Tuf {
return func() *v1alpha1.Tuf {
instance := &v1alpha1.Tuf{}
Expect(cli.Get(ctx, types.NamespacedName{
_ = cli.Get(ctx, types.NamespacedName{
Namespace: ns,
Name: name,
}, instance)).To(Succeed())
}, instance)
return instance
}
}
Expand Down

0 comments on commit 554c12b

Please sign in to comment.