Skip to content
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

Merged
merged 14 commits into from
Jan 23, 2025

Conversation

Prashansa-K
Copy link
Collaborator

@Prashansa-K Prashansa-K commented Dec 20, 2024

Summary

Tests added for new entity: degraphql_routes

Testing

  • Unit tests
  • E2E tests
  • Manual testing on Universal
  • Manual testing on Kubernetes

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 28.11%. Comparing base (2772231) to head (3c09af0).

Files with missing lines Patch % Lines
pkg/file/builder.go 50.00% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Member

@pmalek pmalek left a 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.

targetContent: tt.fields.targetContent,
currentState: tt.fields.currentState,
}
b.build()
Copy link
Member

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()?

@@ -3853,3 +3870,151 @@ func Test_stateBuilder_expressionRoutes_kong370_withKonnect(t *testing.T) {
})
}
}

func Test_stateBuilder_ingestPluginEntities(t *testing.T) {
rand.Seed(42)
Copy link
Member

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.

Copy link
Collaborator Author

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.

degraphqlRoute.Methods = kong.StringSlice("GET")

err := collection.Add(degraphqlRoute)
assert.Nil(err)
Copy link
Member

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?

assert.IsType([]*DegraphqlRoute{}, degraphqlRoutes)
}

func populateDegraphqlRoutes(assert *assert.Assertions,
Copy link
Member

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?

@Prashansa-K Prashansa-K force-pushed the tests/degraphql-routes branch from e97c19e to 00bc3e3 Compare January 22, 2025 08:59
@Prashansa-K Prashansa-K force-pushed the feat/degraphql-routes branch from 2900111 to a01aa3f Compare January 22, 2025 12:36
@Prashansa-K Prashansa-K force-pushed the tests/degraphql-routes branch from 00bc3e3 to 8946072 Compare January 22, 2025 13:31
@Prashansa-K Prashansa-K force-pushed the tests/degraphql-routes branch from 435ebd8 to aeb7d0f Compare January 23, 2025 09:25
@Prashansa-K Prashansa-K force-pushed the tests/degraphql-routes branch from aeb7d0f to 3bcd119 Compare January 23, 2025 09:36
@Prashansa-K Prashansa-K force-pushed the tests/degraphql-routes branch from 3bcd119 to 1ce0758 Compare January 23, 2025 09:42
Base automatically changed from feat/degraphql-routes to main January 23, 2025 12:48
@Prashansa-K Prashansa-K requested a review from pmalek January 23, 2025 13:29
Copy link
Member

@pmalek pmalek left a 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

@@ -389,10 +390,29 @@ func existingFilterChainState() *state.KongState {
return s
}

func existingDegraphqlRouteState() *state.KongState {
s, _ := state.NewKongState()
Copy link
Member

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/file/builder_test.go Outdated Show resolved Hide resolved
pkg/file/builder_test.go Outdated Show resolved Hide resolved
pkg/state/degraphql_route_test.go Outdated Show resolved Hide resolved
Comment on lines 139 to 146
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")
Copy link
Member

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:

Suggested change
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{
...
}

?

@Prashansa-K Prashansa-K requested a review from pmalek January 23, 2025 13:58
@Prashansa-K Prashansa-K merged commit c296111 into main Jan 23, 2025
24 checks passed
@Prashansa-K Prashansa-K deleted the tests/degraphql-routes branch January 23, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants