-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathsearch_test.go
More file actions
139 lines (127 loc) · 3.54 KB
/
Copy pathsearch_test.go
File metadata and controls
139 lines (127 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.
package main
import (
"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.",
"data_streams": [
"datasources.examplelog1",
"datasources.examplelog2",
"datasources.examplemetric"
]
}
],
"categories": [
"custom"
]
}
]
`
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, response)
}))
defer webServer.Close()
fsOpts := packages.FSIndexerOptions{
Logger: testLogger,
}
packagesBasePaths := []string{"./testdata/second_package_path", "./testdata/package"}
indexer := NewCombinedIndexer(
packages.NewZipFileSystemIndexer(fsOpts, "./testdata/local-storage"),
packages.NewFileSystemIndexer(fsOpts, packagesBasePaths...),
)
defer indexer.Close(t.Context())
err := indexer.Init(t.Context())
require.NoError(t, err)
proxyMode, err := proxymode.NewProxyMode(
testLogger,
proxymode.ProxyOptions{
Enabled: true,
ProxyTo: webServer.URL,
},
)
require.NoError(t, err)
searchHandler, err := newSearchHandler(testLogger, indexer, testCacheTime,
searchWithProxy(proxyMode),
)
require.NoError(t, err)
tests := []struct {
endpoint string
path string
file string
handler http.Handler
}{
{"/search?all=true", "/search", "search-all-proxy.json", searchHandler},
{"/search", "/search", "search-just-latest-proxy.json", searchHandler},
}
for _, test := range tests {
t.Run(test.endpoint, func(t *testing.T) {
runEndpoint(t, test.endpoint, test.path, test.file, test.handler)
})
}
}