-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: added tests for degraphql_routes entity #155
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #155 +/- ##
==========================================
+ Coverage 27.27% 28.11% +0.83%
==========================================
Files 109 109
Lines 16967 16976 +9
==========================================
+ Hits 4627 4772 +145
+ Misses 11851 11697 -154
- Partials 489 507 +18 ☔ View full report in Codecov by Sentry. |
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.
Minor nits, otherwise this looks good.
pkg/file/builder_test.go
Outdated
targetContent: tt.fields.targetContent, | ||
currentState: tt.fields.currentState, | ||
} | ||
b.build() |
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.
Any reason we don't check the error returned from build()
?
pkg/file/builder_test.go
Outdated
@@ -3853,3 +3870,151 @@ func Test_stateBuilder_expressionRoutes_kong370_withKonnect(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func Test_stateBuilder_ingestPluginEntities(t *testing.T) { | |||
rand.Seed(42) |
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.
This is deprecated as per: https://pkg.go.dev/math/rand#Seed
Deprecated: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator.
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 have added changes based on the recommendations in rand package. We need that for deterministically generating uuids for the entities.
pkg/state/degraphql_route_test.go
Outdated
degraphqlRoute.Methods = kong.StringSlice("GET") | ||
|
||
err := collection.Add(degraphqlRoute) | ||
assert.Nil(err) |
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.
Nit: I'd consider using require
for these errors, WDYT?
pkg/state/degraphql_route_test.go
Outdated
assert.IsType([]*DegraphqlRoute{}, degraphqlRoutes) | ||
} | ||
|
||
func populateDegraphqlRoutes(assert *assert.Assertions, |
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.
Nit: this is fine but I'd consider passing the t *testing.T
instead of the assert
object as using the latter can potentially (not necessarily) result in an unrelated assert
being used.
IMHO the former is also more idiomatic. WDYT?
e97c19e
to
00bc3e3
Compare
2900111
to
a01aa3f
Compare
00bc3e3
to
8946072
Compare
435ebd8
to
aeb7d0f
Compare
aeb7d0f
to
3bcd119
Compare
3bcd119
to
1ce0758
Compare
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.
Minor nits here and there for consideration
pkg/file/builder_test.go
Outdated
@@ -389,10 +390,29 @@ func existingFilterChainState() *state.KongState { | |||
return s | |||
} | |||
|
|||
func existingDegraphqlRouteState() *state.KongState { | |||
s, _ := state.NewKongState() |
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.
Why not check the error? I'd suggest we consider adding a *testing.T
param and require.NoError(t, err)
here (as well as t.Helper()
to make sure the correct call site of existingDegraphqlRouteState
is printed in the logs). WDYT?
pkg/state/degraphql_route_test.go
Outdated
var degraphqlRoute DegraphqlRoute | ||
degraphqlRoute.ID = kong.String("example") | ||
degraphqlRoute.URI = kong.String("/foo") | ||
degraphqlRoute.Query = kong.String("query { hello }") | ||
degraphqlRoute.Service = &kong.Service{ | ||
ID: kong.String("some-service"), | ||
} | ||
degraphqlRoute.Methods = kong.StringSlice("GET") |
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.
Any reason not to instantiate it like so:
var degraphqlRoute DegraphqlRoute | |
degraphqlRoute.ID = kong.String("example") | |
degraphqlRoute.URI = kong.String("/foo") | |
degraphqlRoute.Query = kong.String("query { hello }") | |
degraphqlRoute.Service = &kong.Service{ | |
ID: kong.String("some-service"), | |
} | |
degraphqlRoute.Methods = kong.StringSlice("GET") | |
var degraphqlRoute := DegraphqlRoute{ | |
... | |
} |
?
Summary
Tests added for new entity: degraphql_routes
Testing