Skip to content

Commit

Permalink
update schema and embetter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mildwonkey committed Oct 29, 2024
1 parent 7ed06c9 commit 2b1875c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/pkg/common/schemas/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,14 @@
"type": "object",
"properties": {
"timeout": {
"type": "integer"
"type": "string"
},
"proxy": {
"type": "string"
},
"headers": {
"type": "array",
"items": {
"type": "string"
}
"type": "object",
"additionalProperties": { "type": "string"}
}
}
},
Expand Down
49 changes: 48 additions & 1 deletion src/pkg/domains/api/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func TestValidateAndMutateOptions(t *testing.T) {
var testTimeout = 10 * time.Second
var zeroTimeout = 0 * time.Second

tests := map[string]struct {
input, want *ApiOpts
expectErrs int
Expand All @@ -32,10 +33,12 @@ func TestValidateAndMutateOptions(t *testing.T) {
&ApiOpts{
Timeout: "10s",
Proxy: "https://my.proxy",
Headers: map[string]string{"cache": "no-cache"},
},
&ApiOpts{
Timeout: "10s",
Proxy: "https://my.proxy",
Headers: map[string]string{"cache": "no-cache"},
timeout: &testTimeout,
proxyURL: &url.URL{
Scheme: "https",
Expand Down Expand Up @@ -86,6 +89,11 @@ func TestValidateAndMutateOptions(t *testing.T) {
}

func TestValidateAndMutateSpec(t *testing.T) {
healthcheckUrl, err := url.Parse("http://example.com/health")
require.NoError(t, err)
testParams := url.Values{}
testParams.Add("key", "value")

tests := map[string]struct {
input, want *ApiSpec
expectErrs int
Expand All @@ -100,6 +108,45 @@ func TestValidateAndMutateSpec(t *testing.T) {
},
1,
},
"success": {
&ApiSpec{
Requests: []Request{
{
Name: "healthcheck",
URL: "http://example.com/health",
Params: map[string]string{
"key": "value",
},
Options: &ApiOpts{
Headers: map[string]string{
"cache-control": "no-hit",
},
},
},
},
},
&ApiSpec{
Requests: []Request{
{
Name: "healthcheck",
URL: "http://example.com/health",
Params: map[string]string{
"key": "value",
},
reqURL: healthcheckUrl,
reqParameters: testParams,
Options: &ApiOpts{
Headers: map[string]string{
"cache-control": "no-hit",
},
timeout: &defaultTimeout,
},
},
},
Options: &ApiOpts{timeout: &defaultTimeout},
},
0,
},
}

for name, test := range tests {
Expand All @@ -122,7 +169,7 @@ func TestValidateAndMutateSpec(t *testing.T) {
}
}

if diff := cmp.Diff(test.want, test.input, cmp.AllowUnexported(ApiSpec{}, ApiOpts{})); diff != "" {
if diff := cmp.Diff(test.want, test.input, cmp.AllowUnexported(ApiSpec{}, ApiOpts{}, Request{})); diff != "" {
t.Fatalf("wrong result(-got +want):\n%s\n", diff)
}
})
Expand Down
7 changes: 4 additions & 3 deletions src/test/e2e/api_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"testing"
"time"

"github.com/defenseunicorns/lula/src/pkg/common/validation"
"github.com/defenseunicorns/lula/src/pkg/message"
"github.com/defenseunicorns/lula/src/test/util"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/features"

"github.com/defenseunicorns/lula/src/pkg/common/validation"
"github.com/defenseunicorns/lula/src/pkg/message"
"github.com/defenseunicorns/lula/src/test/util"
)

func TestApiValidation(t *testing.T) {
Expand Down

0 comments on commit 2b1875c

Please sign in to comment.