-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
mesh: add validation for the new pbmesh resources #18410
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cf970d7
Reduce required type arguments for DecodedResource
mkeeler 75bc5d8
mesh: add validation for the new pbmesh resources
rboyer 55f9027
use consistent casing
rboyer 400c5f6
unbreak the tests
rboyer ea14313
add http route mutation tests
rboyer ae032e5
add tests
rboyer b0ab878
more tests
rboyer a37a7ea
remove todo
rboyer 577faee
finish coverage
rboyer 57a4a2b
add more grpc route tests
rboyer be5fbf7
add another case
rboyer eb59ce7
update signatures
rboyer 8f47382
Update internal/mesh/internal/types/http_route.go
rboyer a7f7c80
validate dest policy enums
rboyer 7e61a8e
validate xroute enums
rboyer 160cfc6
Update internal/mesh/internal/types/grpc_route.go
rboyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,92 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/hashicorp/consul/internal/resource/resourcetest" | ||
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v1alpha1" | ||
"github.com/hashicorp/consul/proto/private/prototest" | ||
"github.com/hashicorp/consul/sdk/testutil" | ||
) | ||
|
||
func TestValidateComputedRoutes(t *testing.T) { | ||
type testcase struct { | ||
routes *pbmesh.ComputedRoutes | ||
expectErr string | ||
} | ||
|
||
run := func(t *testing.T, tc testcase) { | ||
res := resourcetest.Resource(ComputedRoutesType, "api"). | ||
WithData(t, tc.routes). | ||
Build() | ||
|
||
err := ValidateComputedRoutes(res) | ||
|
||
// Verify that validate didn't actually change the object. | ||
got := resourcetest.MustDecode[*pbmesh.ComputedRoutes](t, res) | ||
prototest.AssertDeepEqual(t, tc.routes, got.Data) | ||
|
||
if tc.expectErr == "" { | ||
require.NoError(t, err) | ||
} else { | ||
testutil.RequireErrorContains(t, err, tc.expectErr) | ||
} | ||
} | ||
|
||
cases := map[string]testcase{ | ||
"empty": { | ||
routes: &pbmesh.ComputedRoutes{}, | ||
expectErr: `invalid "ported_configs" field: cannot be empty`, | ||
}, | ||
"empty config": { | ||
routes: &pbmesh.ComputedRoutes{ | ||
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{ | ||
"http": { | ||
Config: nil, | ||
Targets: map[string]*pbmesh.BackendTargetDetails{ | ||
"foo": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectErr: `invalid value of key "http" within ported_configs: invalid "config" field: cannot be empty`, | ||
}, | ||
"empty targets": { | ||
rboyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
routes: &pbmesh.ComputedRoutes{ | ||
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{ | ||
"http": { | ||
Config: &pbmesh.ComputedPortRoutes_Tcp{ | ||
Tcp: &pbmesh.InterpretedTCPRoute{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectErr: `invalid value of key "http" within ported_configs: invalid "targets" field: cannot be empty`, | ||
}, | ||
"valid": { | ||
routes: &pbmesh.ComputedRoutes{ | ||
PortedConfigs: map[string]*pbmesh.ComputedPortRoutes{ | ||
"http": { | ||
Config: &pbmesh.ComputedPortRoutes_Tcp{ | ||
Tcp: &pbmesh.InterpretedTCPRoute{}, | ||
}, | ||
Targets: map[string]*pbmesh.BackendTargetDetails{ | ||
"foo": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
run(t, tc) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to come back to this in NET-5066. I'm not sure how much more validation is required since it is a generated resource type, but we'll likely want a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it probably is. Presumably both the Config and Targets fields should have their internals validated.