Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/component-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ jobs:

- name: Set up Kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-$(uname)-amd64
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-linux-amd64
chmod +x ./kind
./kind create cluster
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/linux/amd64/kubectl
curl -LO "https://dl.k8s.io/release/v1.35.0/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
- name: Install Helm and Kubectl
Expand Down
8 changes: 4 additions & 4 deletions tests/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,22 @@ func Test_07_RuleBindingApplyTest(t *testing.T) {
}

// valid
exitCode := testutils.RunCommand("kubectl", "apply", "-f", ruleBindingPath("all-valid.yaml"))
exitCode := testutils.RunCommand("kubectl", "apply", "--validate=false", "-f", ruleBindingPath("all-valid.yaml"))
assert.Equal(t, 0, exitCode, "Error applying valid rule binding")
exitCode = testutils.RunCommand("kubectl", "delete", "-f", ruleBindingPath("all-valid.yaml"))
require.Equal(t, 0, exitCode, "Error deleting valid rule binding")

// duplicate fields
file := ruleBindingPath("dup-fields-name-tag.yaml")
exitCode = testutils.RunCommand("kubectl", "apply", "-f", file)
exitCode = testutils.RunCommand("kubectl", "apply", "--validate=false", "-f", file)
assert.NotEqualf(t, 0, exitCode, "Expected error when applying rule binding '%s'", file)

file = ruleBindingPath("dup-fields-name-id.yaml")
exitCode = testutils.RunCommand("kubectl", "apply", "-f", file)
exitCode = testutils.RunCommand("kubectl", "apply", "--validate=false", "-f", file)
assert.NotEqualf(t, 0, exitCode, "Expected error when applying rule binding '%s'", file)

file = ruleBindingPath("dup-fields-id-tag.yaml")
exitCode = testutils.RunCommand("kubectl", "apply", "-f", file)
exitCode = testutils.RunCommand("kubectl", "apply", "--validate=false", "-f", file)
assert.NotEqualf(t, 0, exitCode, "Expected error when applying rule binding '%s'", file)
}

Expand Down
8 changes: 7 additions & 1 deletion tests/testutils/utils.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package testutils

import (
"bytes"
"errors"
"fmt"
"io"
"os/exec"
)

func RunCommand(name string, args ...string) int {
cmd := exec.Command(name, args...)
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
var exiterr *exec.ExitError
if errors.As(err, &exiterr) {
if stderr.Len() > 0 {
fmt.Printf("Command '%s %v' failed: %s\n", name, args, stderr.String())
}
return exiterr.ExitCode()
}
}
Expand Down
Loading