-
Notifications
You must be signed in to change notification settings - Fork 67
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
Return just the latest version of the packages if all=true is not set when proxy mode is enabled #1055
Merged
Merged
Return just the latest version of the packages if all=true is not set when proxy mode is enabled #1055
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/package-registry/packages" | ||
"github.com/elastic/package-registry/proxymode" | ||
) | ||
|
||
func TestSearchWithProxyMode(t *testing.T) { | ||
|
||
// nginx 1.15.0 is not included as part of the local packages | ||
// datasources 1.0.0 is included as part of the local packages | ||
webServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
response := ` | ||
[ | ||
{ | ||
"name": "nginx", | ||
"title": "Nginx", | ||
"version": "1.15.0", | ||
"release": "ga", | ||
"description": "Collect logs and metrics from Nginx HTTP servers with Elastic Agent.", | ||
"type": "integration", | ||
"download": "/epr/nginx/nginx-1.15.0.zip", | ||
"path": "/package/nginx/1.15.0", | ||
"icons": [ | ||
{ | ||
"src": "/img/logo_nginx.svg", | ||
"path": "/package/nginx/1.15.0/img/logo_nginx.svg", | ||
"title": "logo nginx", | ||
"size": "32x32", | ||
"type": "image/svg+xml" | ||
} | ||
], | ||
"policy_templates": [ | ||
{ | ||
"name": "nginx", | ||
"title": "Nginx logs and metrics", | ||
"description": "Collect logs and metrics from Nginx instances" | ||
} | ||
], | ||
"conditions": { | ||
"kibana": { | ||
"version": "^8.8.0" | ||
} | ||
}, | ||
"owner": { | ||
"github": "elastic/obs-infraobs-integrations" | ||
}, | ||
"categories": [ | ||
"web", | ||
"observability" | ||
], | ||
"signature_path": "/epr/nginx/nginx-1.15.0.zip.sig" | ||
}, | ||
{ | ||
"name": "datasources", | ||
"title": "Default datasource Integration", | ||
"version": "1.0.0", | ||
"release": "beta", | ||
"description": "Package with data sources", | ||
"type": "integration", | ||
"download": "/epr/datasources/datasources-1.0.0.zip", | ||
"path": "/package/datasources/1.0.0", | ||
"policy_templates": [ | ||
{ | ||
"name": "nginx", | ||
"title": "Datasource title", | ||
"description": "Details about the data source." | ||
} | ||
], | ||
"categories": [ | ||
"custom" | ||
] | ||
} | ||
] | ||
` | ||
w.Header().Set("Content-Type", "application/json") | ||
fmt.Fprintln(w, response) | ||
})) | ||
defer webServer.Close() | ||
|
||
packagesBasePaths := []string{"./testdata/second_package_path", "./testdata/package"} | ||
indexer := NewCombinedIndexer( | ||
packages.NewZipFileSystemIndexer(testLogger, "./testdata/local-storage"), | ||
packages.NewFileSystemIndexer(testLogger, packagesBasePaths...), | ||
) | ||
|
||
err := indexer.Init(context.Background()) | ||
require.NoError(t, err) | ||
|
||
proxyMode, err := proxymode.NewProxyMode( | ||
testLogger, | ||
proxymode.ProxyOptions{ | ||
Enabled: true, | ||
ProxyTo: webServer.URL, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
searchWithProxyHandler := searchHandlerWithProxyMode(testLogger, indexer, proxyMode, testCacheTime) | ||
tests := []struct { | ||
endpoint string | ||
path string | ||
file string | ||
handler func(w http.ResponseWriter, r *http.Request) | ||
}{ | ||
{"/search?all=true", "/search", "search-all-proxy.json", searchWithProxyHandler}, | ||
{"/search", "/search", "search-just-latest-proxy.json", searchWithProxyHandler}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.endpoint, func(t *testing.T) { | ||
runEndpoint(t, test.endpoint, test.path, test.file, test.handler) | ||
}) | ||
} | ||
} |
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.
Do we have tests covered by this? I would be interested on seeing that we don't duplicate packages, but
packages.Join
should take care of this.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.
There were no tests for this proxy mode in search endpoint.
I've added a test here 54d32e7 using proxy mode using all=true and not using it.