-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): refactor integration tests so that assess funcs can …
…accept stepfuncs.Option
- Loading branch information
Showing
5 changed files
with
238 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package stepfuncs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/e2e-framework/klient/k8s" | ||
"sigs.k8s.io/e2e-framework/klient/k8s/resources" | ||
|
||
"github.com/SumoLogic/sumologic-kubernetes-collection/tests/integration/internal/ctxopts" | ||
) | ||
|
||
type Option interface { | ||
Apply(ctx context.Context, obj k8s.Object) | ||
GetListOption(ctx context.Context) resources.ListOption | ||
} | ||
|
||
type nameOption struct { | ||
name string | ||
} | ||
|
||
func (no nameOption) Apply(ctx context.Context, obj k8s.Object) { | ||
obj.SetName(no.name) | ||
} | ||
|
||
func (no nameOption) GetListOption(ctx context.Context) resources.ListOption { | ||
return func(lo *metav1.ListOptions) {} | ||
} | ||
|
||
func WithName(name string) Option { | ||
return nameOption{ | ||
name: name, | ||
} | ||
} | ||
|
||
type nameFOption struct { | ||
formatter Formatter | ||
} | ||
|
||
func (no nameFOption) Apply(ctx context.Context, obj k8s.Object) { | ||
obj.SetName(no.formatter(ctx)) | ||
} | ||
|
||
func (no nameFOption) GetListOption(ctx context.Context) resources.ListOption { | ||
return func(lo *metav1.ListOptions) { | ||
} | ||
} | ||
|
||
func WithNameF(formatter Formatter) Option { | ||
return nameFOption{ | ||
formatter: formatter, | ||
} | ||
} | ||
|
||
type LabelFormatterKV struct { | ||
K string | ||
V Formatter | ||
} | ||
|
||
type labeslFOption struct { | ||
kvs []LabelFormatterKV | ||
} | ||
|
||
func (lo labeslFOption) Apply(ctx context.Context, obj k8s.Object) { | ||
labels := make(map[string]string, len(lo.kvs)) | ||
for _, elem := range lo.kvs { | ||
labels[elem.K] = elem.V(ctx) | ||
} | ||
obj.SetLabels(labels) | ||
} | ||
|
||
func (lo labeslFOption) GetListOption(ctx context.Context) resources.ListOption { | ||
labels := make([]string, 0, len(lo.kvs)) | ||
for _, elem := range lo.kvs { | ||
labels = append(labels, fmt.Sprintf("%s=%s", elem.K, elem.V(ctx))) | ||
} | ||
|
||
return resources.WithLabelSelector(strings.Join(labels, ",")) | ||
} | ||
|
||
func WithLabelsF(kvs ...LabelFormatterKV) Option { | ||
return labeslFOption{ | ||
kvs: kvs, | ||
} | ||
} | ||
|
||
type Formatter func(ctx context.Context) string | ||
|
||
func ReleaseFormatter(format string) Formatter { | ||
return func(ctx context.Context) string { | ||
return fmt.Sprintf(format, ctxopts.HelmRelease(ctx)) | ||
} | ||
} |