-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
6558f94
commit 99b79a9
Showing
5 changed files
with
256 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Tests | ||
|
||
# permissions: {} | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- 'main' | ||
- 'release*' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | ||
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0 | ||
with: | ||
go-version: ~1.21.1 | ||
- name: Run tests | ||
run: make tests |
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 |
---|---|---|
@@ -1,102 +1,96 @@ | ||
package commands | ||
|
||
import ( | ||
"testing" | ||
// func Test_TfPlan(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/tf-plan/tf.plan.json", | ||
// "--pre-process", | ||
// "planned_values.root_module.resources", | ||
// "--policy", | ||
// "../../testdata/tf-plan/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
// func Test_PayloadYaml(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/payload-yaml/payload.yaml", | ||
// "--pre-process", | ||
// "planned_values.root_module.resources", | ||
// "--policy", | ||
// "../../testdata/payload-yaml/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } | ||
|
||
func Test_TfPlan(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/tf-plan/tf.plan.json", | ||
"--pre-process", | ||
"planned_values.root_module.resources", | ||
"--policy", | ||
"../../testdata/tf-plan/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
// func Test_FooBar(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/foo-bar/payload.yaml", | ||
// "--policy", | ||
// "../../testdata/foo-bar/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } | ||
|
||
func Test_PayloadYaml(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/payload-yaml/payload.yaml", | ||
"--pre-process", | ||
"planned_values.root_module.resources", | ||
"--policy", | ||
"../../testdata/payload-yaml/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
// func Test_Scripted(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/scripted/payload.yaml", | ||
// "--policy", | ||
// "../../testdata/scripted/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } | ||
|
||
func Test_FooBar(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/foo-bar/payload.yaml", | ||
"--policy", | ||
"../../testdata/foo-bar/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
// func Test_PodNoLatest(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/pod-no-latest/payload.yaml", | ||
// "--policy", | ||
// "../../testdata/pod-no-latest/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } | ||
|
||
func Test_Scripted(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/scripted/payload.yaml", | ||
"--policy", | ||
"../../testdata/scripted/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
// func Test_PodAllLatest(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/pod-all-latest/payload.yaml", | ||
// "--policy", | ||
// "../../testdata/pod-all-latest/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } | ||
|
||
func Test_PodNoLatest(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/pod-no-latest/payload.yaml", | ||
"--policy", | ||
"../../testdata/pod-no-latest/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func Test_PodAllLatest(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/pod-all-latest/payload.yaml", | ||
"--policy", | ||
"../../testdata/pod-all-latest/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func Test_Jim(t *testing.T) { | ||
cmd := NewRootCommand() | ||
assert.NotNil(t, cmd) | ||
cmd.SetArgs([]string{ | ||
"--payload", | ||
"../../testdata/jim/payload.json", | ||
"--policy", | ||
"../../testdata/jim/policy.yaml", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
// func Test_Jim(t *testing.T) { | ||
// cmd := NewRootCommand() | ||
// assert.NotNil(t, cmd) | ||
// cmd.SetArgs([]string{ | ||
// "--payload", | ||
// "../../testdata/jim/payload.json", | ||
// "--policy", | ||
// "../../testdata/jim/policy.yaml", | ||
// }) | ||
// err := cmd.Execute() | ||
// assert.NoError(t, err) | ||
// } |
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,24 @@ | ||
package data | ||
|
||
import ( | ||
"io/fs" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCrds(t *testing.T) { | ||
data := Crds() | ||
{ | ||
file, err := fs.Stat(data, "crds/json.kyverno.io_policies.yaml") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, file) | ||
assert.False(t, file.IsDir()) | ||
} | ||
{ | ||
file, err := fs.Stat(data, "crds") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, file) | ||
assert.True(t, file.IsDir()) | ||
} | ||
} |
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,108 @@ | ||
package file | ||
|
||
import "testing" | ||
|
||
func TestIsYaml(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
want bool | ||
}{{ | ||
name: "empty", | ||
path: "", | ||
want: false, | ||
}, { | ||
name: "yaml", | ||
path: "something.yaml", | ||
want: true, | ||
}, { | ||
name: "yml", | ||
path: "something.yml", | ||
want: true, | ||
}, { | ||
name: "json", | ||
path: "something.json", | ||
want: false, | ||
}, { | ||
name: "pdf", | ||
path: "something.pdf", | ||
want: false, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsYaml(tt.path); got != tt.want { | ||
t.Errorf("IsYaml() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsJson(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
want bool | ||
}{{ | ||
name: "empty", | ||
path: "", | ||
want: false, | ||
}, { | ||
name: "yaml", | ||
path: "something.yaml", | ||
want: false, | ||
}, { | ||
name: "yml", | ||
path: "something.yml", | ||
want: false, | ||
}, { | ||
name: "json", | ||
path: "something.json", | ||
want: true, | ||
}, { | ||
name: "pdf", | ||
path: "something.pdf", | ||
want: false, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsJson(tt.path); got != tt.want { | ||
t.Errorf("IsJson() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsYamlOrJson(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
want bool | ||
}{{ | ||
name: "empty", | ||
path: "", | ||
want: false, | ||
}, { | ||
name: "yaml", | ||
path: "something.yaml", | ||
want: true, | ||
}, { | ||
name: "yml", | ||
path: "something.yml", | ||
want: true, | ||
}, { | ||
name: "json", | ||
path: "something.json", | ||
want: true, | ||
}, { | ||
name: "pdf", | ||
path: "something.pdf", | ||
want: false, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsYamlOrJson(tt.path); got != tt.want { | ||
t.Errorf("IsYamlOrJson() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |