-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Testing: move tests into black box scope #6605
base: master
Are you sure you want to change the base?
Conversation
A JIRA Issue ID is missing from your branch name, PR title and PR description! 🦄 Your branch: tests/blackbox Your PR title: Testing: move tests into black box scope Your PR description: The PR tries to refactor tests away from the gateway package using black box package scope. The source set has been limited to only the test files which contain `StartTest`, a known entrypoint for integration tests, but some post processing increased the number from 21 to 31 tests (by size, from smallest). Black box tests only allow accessing public symbols from the package. Limiting factor: big test files are notoriously hard to extract due to a lot of couplings, while smaller test functions could be moved. After the change: Blackbox tests size: 186496/1239669 (15.04% of total package) bash script to calculate black box tests metrics
If this is your first time contributing to this repository - welcome! Please refer to jira-lint to get started. Without the JIRA Issue ID in your branch name you would lose out on automatic updates to JIRA via SCM; some GitHub status checks might fail. Valid sample branch names:‣ feature/shiny-new-feature--mojo-10' |
API Changes --- prev.txt 2024-10-22 08:10:40.502668330 +0000
+++ current.txt 2024-10-22 08:10:34.258602491 +0000
@@ -7974,6 +7974,9 @@
)
const BackupApiKeyBase = "node-definition-backup:"
const BackupPolicyKeyBase = "node-policy-backup:"
+const (
+ CachedResponseHeader = "x-tyk-cached-response"
+)
const CoProcessDefaultKeyPrefix = "coprocess-data:"
CoProcessDefaultKeyPrefix is used as a key prefix for this CP.
@@ -8141,6 +8144,7 @@
func Start()
func TestReq(t testing.TB, method, urlStr string, body interface{}) *http.Request
func TestReqBody(t testing.TB, body interface{}) io.Reader
+func TransformBody(r *http.Request, tmeta *TransformSpec, t *TransformMiddleware) error
func TykGetData(CKey *C.char) *C.char
TykGetData is a CoProcess API function for fetching data.
@@ -8955,6 +8959,8 @@
func (gw *Gateway) BuildAndLoadAPI(apiGens ...func(spec *APISpec)) (specs []*APISpec)
+func (gw *Gateway) BuildDashboardConnStr(resource string) string
+
func (gw *Gateway) CoProcessInit()
CoProcessInit creates a new CoProcessDispatcher, it will be called when Tyk
starts.
@@ -8985,6 +8991,9 @@
func (gw *Gateway) GetStorageForApi(apiID string) (ExtendedOsinStorageInterface, int, error)
+func (gw *Gateway) HandleRedisEvent(v interface{}, handled func(NotificationCommand), reloaded func())
+ HandleRedisEvent is exported for test usage.
+
func (gw *Gateway) InitHostCheckManager(ctx context.Context, store storage.Handler)
func (gw *Gateway) LoadAPI(specs ...*APISpec) (out []*APISpec)
@@ -9274,7 +9283,7 @@
type HeaderTransform struct {
BaseTykResponseHandler
- // Has unexported fields.
+ Config HeaderTransformOptions
}
func (h *HeaderTransform) Base() *BaseTykResponseHandler
@@ -10806,6 +10815,15 @@
Form map[string]string
}
+type TraceHttpRequest struct {
+ Method string `json:"method"`
+ Path string `json:"path"`
+ Body string `json:"body"`
+ Headers http.Header `json:"headers"`
+}
+
+func (tr *TraceHttpRequest) ToRequest(ignoreCanonicalMIMEHeaderKey bool) (*http.Request, error)
+
type TraceMiddleware struct {
TykMiddleware
} |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Quality Gate failedFailed conditions |
User description
The PR tries to refactor tests away from the gateway package using black box package scope. The source set has been limited to only the test files which contain
StartTest
, a known entrypoint for integration tests, but some post processing increased the number from 21 to 31 tests (by size, from smallest).Black box tests only allow accessing public symbols from the package.
Limiting factor: big test files are notoriously hard to extract due to a lot of couplings, while smaller test functions could be moved.
After the change:
Blackbox tests size: 186496/1239669 (15.04% of total package)
Blackbox test functions: 140/760 (18.42% of total functions)
Blackbox test files: 31/83 (37.35% of total test files)
bash script to calculate black box tests metrics
PR Type
Tests, Enhancement
Description
httputil
for CORS headers and basic auth.Changes walkthrough 📝
3 files
blackbox_test.go
Introduce black box testing with symbol shims
gateway/blackbox_test.go
blackbox_test.go
for black box testing.gateway
package for testing.testutil_test.go
Add test utility functions for various test preparations
gateway/testutil_test.go
vars middleware, and virtual endpoints.
tracing_test.go
Update tracing tests to use exported TraceHttpRequest
gateway/tracing_test.go
TraceHttpRequest
and itsToRequest
method.11 files
headers.go
Add utility functions for CORS headers and basic auth
internal/httputil/headers.go
CORSHeaders
variable for common CORS headers.AuthHeader
function for generating basic auth headers.listen_proxy_proto.go
Introduce proxy protocol listener utility for tests
internal/httputil/listen_proxy_proto.go
TestListenProxyProto
function as a test utility for proxyprotocol.
api_definition_test.go
Update method calls to use exported HandleRedisEvent
gateway/api_definition_test.go
HandleRedisEvent
.api_test.go
Refactor test preparation and context session setting
gateway/api_test.go
TestPrepareBasicAuth
.ctxSetSession
withctx.SetSession
.auth_manager_test.go
Use httputil for authorization header generation
gateway/auth_manager_test.go
httputil
forAuthHeader
usage.dashboard_register.go
Refactor to use BuildDashboardConnStr for connection strings
gateway/dashboard_register.go
BuildDashboardConnStr
.mw_basic_auth_test.go
Refactor basic auth tests to use httputil
gateway/mw_basic_auth_test.go
httputil.AuthHeader
.TestPrepareBasicAuth
.mw_context_vars_test.go
Refactor context vars middleware test preparation
gateway/mw_context_vars_test.go
TestPrepareContextVarsMiddleware
.mw_virtual_endpoint_test.go
Refactor virtual endpoint tests with new utilities
gateway/mw_virtual_endpoint_test.go
TestPrepareVirtualEndpoint
.cachedResponseHeader
withCachedResponseHeader
.redis_signals.go
Export HandleRedisEvent and simplify pubsub delay logic
gateway/redis_signals.go
HandleRedisEvent
for test usage.addPubSubDelay
function and inlined its logic.tracing.go
Export TraceHttpRequest for external usage
gateway/tracing.go
TraceHttpRequest
and its methodToRequest
.