-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix: correctly handle route schema defaults with Konnect #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2755,3 +2755,93 @@ func Test_getStripPathBasedOnProtocols(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func Test_stateBuilder_ingestRouteKonnect(t *testing.T) { | ||
assert := assert.New(t) | ||
rand.Seed(42) | ||
type fields struct { | ||
currentState *state.KongState | ||
} | ||
type args struct { | ||
route FRoute | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
wantErr bool | ||
wantState *utils.KongRawState | ||
}{ | ||
{ | ||
name: "traditional route", | ||
fields: fields{ | ||
currentState: emptyState(), | ||
}, | ||
args: args{ | ||
route: FRoute{ | ||
Route: kong.Route{ | ||
Name: kong.String("foo"), | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
wantState: &utils.KongRawState{ | ||
Routes: []*kong.Route{ | ||
{ | ||
ID: kong.String("538c7f96-b164-4f1b-97bb-9f4bb472e89f"), | ||
Name: kong.String("foo"), | ||
PreserveHost: kong.Bool(false), | ||
RegexPriority: kong.Int(0), | ||
StripPath: kong.Bool(false), | ||
Protocols: kong.StringSlice("http", "https"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "expression route", | ||
fields: fields{ | ||
currentState: emptyState(), | ||
}, | ||
args: args{ | ||
route: FRoute{ | ||
Route: kong.Route{ | ||
Name: kong.String("foo"), | ||
Expression: kong.String(`'(http.path == "/test") || (http.path ^= "/test/")'`), | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
wantState: &utils.KongRawState{ | ||
Routes: []*kong.Route{ | ||
{ | ||
ID: kong.String("5b1484f2-5209-49d9-b43e-92ba09dd9d52"), | ||
Name: kong.String("foo"), | ||
PreserveHost: kong.Bool(false), | ||
Expression: kong.String(`'(http.path == "/test") || (http.path ^= "/test/")'`), | ||
Priority: kong.Uint64(0), | ||
StripPath: kong.Bool(false), | ||
Protocols: kong.StringSlice("http", "https"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx := context.Background() | ||
b := &stateBuilder{ | ||
currentState: tt.fields.currentState, | ||
isKonnect: true, | ||
} | ||
b.rawState = &utils.KongRawState{} | ||
d, _ := utils.GetDefaulter(ctx, defaulterTestOpts) | ||
b.defaulter = d | ||
b.intermediate, _ = state.NewKongState() | ||
Comment on lines
+2838
to
+2840
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too late to the party but any particular reason not to check the errors here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be done, but not meaningful for the specific test...copy&pasta mistake |
||
if err := b.ingestRoute(tt.args.route); (err != nil) != tt.wantErr { | ||
t.Errorf("stateBuilder.ingestRoute() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
assert.Equal(tt.wantState, b.rawState) | ||
}) | ||
} | ||
} |
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.
traditiona
->traditional
🙃