Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: names package (cherry-pick #1695) #1697

Merged
merged 1 commit into from
Jul 23, 2024
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
5 changes: 2 additions & 3 deletions pkg/runner/names/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path/filepath"

"github.com/kyverno/chainsaw/pkg/discovery"
"github.com/kyverno/chainsaw/pkg/model"
)

type (
Expand All @@ -16,11 +15,11 @@ type (
relativePathInterface = func(string, string) (string, error)
)

func Test(config model.Configuration, test discovery.Test) (string, error) {
func Test(full bool, test discovery.Test) (string, error) {
if test.Test == nil {
return "", errors.New("test must not be nil")
}
if !config.Discovery.FullName {
if !full {
return test.Test.GetName(), nil
}
return helpTest(test, nil, nil, nil)
Expand Down
35 changes: 7 additions & 28 deletions pkg/runner/names/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"

"github.com/kyverno/chainsaw/pkg/apis/v1alpha2"
"github.com/kyverno/chainsaw/pkg/discovery"
"github.com/kyverno/chainsaw/pkg/model"
"github.com/stretchr/testify/assert"
Expand All @@ -18,29 +17,21 @@ func TestTest(t *testing.T) {
assert.NoError(t, err)
tests := []struct {
name string
config model.Configuration
full bool
test discovery.Test
want string
wantErr bool
}{{
name: "nil test",
config: model.Configuration{
Discovery: v1alpha2.DiscoveryOptions{
FullName: false,
},
},
full: false,
test: discovery.Test{
BasePath: cwd,
Test: nil,
},
wantErr: true,
}, {
name: "no full name",
config: model.Configuration{
Discovery: v1alpha2.DiscoveryOptions{
FullName: false,
},
},
full: false,
test: discovery.Test{
BasePath: cwd,
Test: &model.Test{
Expand All @@ -53,11 +44,7 @@ func TestTest(t *testing.T) {
want: "foo",
}, {
name: "full name",
config: model.Configuration{
Discovery: v1alpha2.DiscoveryOptions{
FullName: true,
},
},
full: true,
test: discovery.Test{
BasePath: cwd,
Test: &model.Test{
Expand All @@ -70,11 +57,7 @@ func TestTest(t *testing.T) {
want: ".[foo]",
}, {
name: "full name",
config: model.Configuration{
Discovery: v1alpha2.DiscoveryOptions{
FullName: true,
},
},
full: true,
test: discovery.Test{
BasePath: filepath.Join(cwd, "..", "dir", "dir"),
Test: &model.Test{
Expand All @@ -87,11 +70,7 @@ func TestTest(t *testing.T) {
want: "../dir/dir[foo]",
}, {
name: "full name",
config: model.Configuration{
Discovery: v1alpha2.DiscoveryOptions{
FullName: true,
},
},
full: true,
test: discovery.Test{
BasePath: filepath.Join(cwd, "dir", "dir"),
Test: &model.Test{
Expand All @@ -105,7 +84,7 @@ func TestTest(t *testing.T) {
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Test(tt.config, tt.test)
got, err := Test(tt.full, tt.test)
if tt.wantErr {
assert.Error(t, err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/processors/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (p *testsProcessor) Run(ctx context.Context, bindings binding.Bindings) {
shouldFailFast := &atomic.Bool{}
for i := range p.tests {
test := p.tests[i]
name, err := names.Test(p.config, test)
name, err := names.Test(p.config.Discovery.FullName, test)
if err != nil {
logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err))
failer.FailNow(ctx)
Expand Down
Loading