Skip to content

Commit

Permalink
fix: add pet namespace if necessary
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Oct 13, 2023
1 parent 01da390 commit 8fe05e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Create test cluster
run: make kind-cluster
- name: Run tests
run: make tests
- name: Upload Report to Codecov
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"k8s.io/apimachinery/pkg/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth" // package needed for auth providers like GCP
"k8s.io/client-go/rest"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -9,6 +10,7 @@ import (
type Client interface {
ctrlclient.Reader
ctrlclient.Writer
IsObjectNamespaced(obj runtime.Object) (bool, error)
}

func New(cfg *rest.Config) (Client, error) {
Expand Down
16 changes: 13 additions & 3 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,30 @@ func runTest(t *testing.T, cfg *rest.Config, test discovery.Test) {
step := test.Spec.Steps[i]
t.Run(fmt.Sprintf("step-%d", i+1), func(t *testing.T) {
t.Helper()
executeStep(t, test.BasePath, step, c)
executeStep(t, test.BasePath, namespace.Name, step, c)
})
}
}

func executeStep(t *testing.T, basePath string, step v1alpha1.TestStepSpec, c client.Client) {
func executeStep(t *testing.T, basePath string, namespace string, step v1alpha1.TestStepSpec, c client.Client) {
t.Helper()
for _, apply := range step.Apply {
resources, err := resource.Load(filepath.Join(basePath, apply.File))
if err != nil {
t.Fatal(err)
}
for i := range resources {
_, err := client.CreateOrUpdate(context.Background(), c, &resources[i])
resource := &resources[i]
if resource.GetNamespace() == "" {
namespaced, err := c.IsObjectNamespaced(resource)
if err != nil {
t.Fatal(err)
}
if namespaced {
resource.SetNamespace(namespace)
}
}
_, err := client.CreateOrUpdate(context.Background(), c, resource)
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion testdata/tests/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: chainsaw-quick-start
namespace: default
data:
foo: bar

0 comments on commit 8fe05e0

Please sign in to comment.