generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Flatten validating webhook packages (#1607)
- Loading branch information
Showing
26 changed files
with
730 additions
and
1,293 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
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
15 changes: 2 additions & 13 deletions
15
...logpipeline/validation/files_validator.go → webhook/logpipeline/files_validator.go
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,71 @@ | ||
package logpipeline | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
||
telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1" | ||
testutils "github.com/kyma-project/telemetry-manager/internal/utils/test" | ||
) | ||
|
||
func TestDuplicateFileName(t *testing.T) { | ||
scheme := runtime.NewScheme() | ||
_ = clientgoscheme.AddToScheme(scheme) | ||
_ = telemetryv1alpha1.AddToScheme(scheme) | ||
|
||
existingPipeline := testutils.NewLogPipelineBuilder().WithName("foo").WithFile("f1.json", "").Build() | ||
|
||
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&existingPipeline).Build() | ||
|
||
sut := NewValidatingWebhookHandler(fakeClient, scheme) | ||
|
||
newPipeline := testutils.NewLogPipelineBuilder().WithName("bar").WithFile("f1.json", "").Build() | ||
|
||
response := sut.Handle(context.Background(), admissionRequestFrom(t, newPipeline)) | ||
|
||
require.False(t, response.Allowed) | ||
require.EqualValues(t, response.Result.Code, http.StatusBadRequest) | ||
require.Equal(t, response.Result.Message, "filename 'f1.json' is already being used in the logPipeline 'foo'") | ||
} | ||
|
||
func TestDuplicateFileNameInSamePipeline(t *testing.T) { | ||
scheme := runtime.NewScheme() | ||
_ = clientgoscheme.AddToScheme(scheme) | ||
_ = telemetryv1alpha1.AddToScheme(scheme) | ||
|
||
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects().Build() | ||
|
||
sut := NewValidatingWebhookHandler(fakeClient, scheme) | ||
|
||
newPipeline := testutils.NewLogPipelineBuilder().WithName("foo").WithFile("f1.json", "").WithFile("f1.json", "").Build() | ||
|
||
response := sut.Handle(context.Background(), admissionRequestFrom(t, newPipeline)) | ||
|
||
require.False(t, response.Allowed) | ||
require.EqualValues(t, response.Result.Code, http.StatusBadRequest) | ||
require.Equal(t, response.Result.Message, "duplicate file names detected please review your pipeline") | ||
} | ||
|
||
func TestValidateUpdatePipeline(t *testing.T) { | ||
scheme := runtime.NewScheme() | ||
_ = clientgoscheme.AddToScheme(scheme) | ||
_ = telemetryv1alpha1.AddToScheme(scheme) | ||
|
||
existingPipeline := testutils.NewLogPipelineBuilder().WithName("foo").WithFile("f1.json", "").Build() | ||
|
||
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&existingPipeline).Build() | ||
|
||
sut := NewValidatingWebhookHandler(fakeClient, scheme) | ||
|
||
newPipeline := testutils.NewLogPipelineBuilder().WithName("foo").WithFile("f1.json", "").Build() | ||
|
||
response := sut.Handle(context.Background(), admissionRequestFrom(t, newPipeline)) | ||
|
||
require.True(t, response.Allowed) | ||
} |
Oops, something went wrong.