-
Notifications
You must be signed in to change notification settings - Fork 84
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: Frank Jogeleit <frank.jogeleit@lovoo.com>
- Loading branch information
Frank Jogeleit
committed
Apr 28, 2024
1 parent
48d5c0f
commit 76797be
Showing
10 changed files
with
150 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package helper_test | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/kyverno/policy-reporter/pkg/helper" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSendJSONResponse(t *testing.T) { | ||
t.Run("success response", func(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
|
||
helper.SendJSONResponse(w, []string{"default", "user"}, nil) | ||
|
||
assert.Equal(t, http.StatusOK, w.Code) | ||
|
||
resp := make([]string, 0, 2) | ||
|
||
json.NewDecoder(w.Body).Decode(&resp) | ||
|
||
assert.Equal(t, []string{"default", "user"}, resp) | ||
}) | ||
|
||
t.Run("error response", func(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
|
||
helper.SendJSONResponse(w, nil, errors.New("error")) | ||
|
||
assert.Equal(t, http.StatusInternalServerError, w.Code) | ||
|
||
resp := make(map[string]string, 0) | ||
|
||
json.NewDecoder(w.Body).Decode(&resp) | ||
|
||
assert.Equal(t, map[string]string{"message": "error"}, resp) | ||
}) | ||
} |
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,48 @@ | ||
package helper_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kyverno/policy-reporter/pkg/helper" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestContains(t *testing.T) { | ||
assert.True(t, helper.Contains("kyverno", []string{"test", "kyverno", "trivy"})) | ||
assert.False(t, helper.Contains("kube-bench", []string{"test", "kyverno", "trivy"})) | ||
} | ||
|
||
func TestToList(t *testing.T) { | ||
assert.Equal(t, []string{"kyverno", "trivy"}, helper.ToList(map[string]string{ | ||
"first": "kyverno", | ||
"second": "trivy", | ||
})) | ||
} | ||
|
||
func TestMap(t *testing.T) { | ||
assert.Equal(t, []string{"kyverno", "trivy"}, helper.Map([]string{"source_kyverno", "source_trivy"}, func(value string) string { | ||
return strings.TrimPrefix(value, "source_") | ||
})) | ||
} | ||
|
||
func TestConvertMap(t *testing.T) { | ||
assert.Equal(t, map[string]string{"first": "kyverno", "second": "trivy"}, helper.ConvertMap(map[string]any{ | ||
"first": "kyverno", | ||
"second": "trivy", | ||
"third": 3, | ||
})) | ||
} | ||
|
||
func TestDetauls(t *testing.T) { | ||
assert.Equal(t, "fallback", helper.Defaults("", "fallback")) | ||
assert.Equal(t, "value", helper.Defaults("value", "fallback")) | ||
} | ||
|
||
func TestToPointer(t *testing.T) { | ||
value := "test" | ||
number := 5 | ||
|
||
assert.Equal(t, &value, helper.ToPointer(value)) | ||
assert.Equal(t, &number, helper.ToPointer(number)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package aws_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kyverno/policy-reporter/pkg/helper" | ||
"github.com/kyverno/policy-reporter/pkg/target/provider/aws" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestS3Client(t *testing.T) { | ||
client := aws.NewS3Client("access", "secret", "eu-central-1", "http://s3.aws.com", "policy-reporter", false, aws.WithKMS(true, helper.ToPointer("kms"), helper.ToPointer("encryption"))) | ||
|
||
assert.NotNil(t, client) | ||
} | ||
|
||
func TestKinesisClient(t *testing.T) { | ||
client := aws.NewKinesisClient("access", "secret", "eu-central-1", "http://kinesis.aws.com", "policy-reporter") | ||
|
||
assert.NotNil(t, client) | ||
} | ||
|
||
func TestSecurityHubClient(t *testing.T) { | ||
client := aws.NewHubClient("access", "secret", "eu-central-1", "http://securityhub.aws.com") | ||
|
||
assert.NotNil(t, client) | ||
} |
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