@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
"strings"
12
12
13
+ "github.com/elastic/elastic-package/internal/common"
13
14
"github.com/elastic/elastic-package/internal/kibana"
14
15
"github.com/elastic/elastic-package/internal/logger"
15
16
"github.com/elastic/elastic-package/internal/packages"
@@ -130,6 +131,11 @@ func (r *tester) run(ctx context.Context) ([]testrunner.TestResult, error) {
130
131
}
131
132
installedAssets := installedPackage .Assets ()
132
133
134
+ installedTags , err := r .kibanaClient .ExportSavedObjects (ctx , kibana.ExportSavedObjectsRequest {Type : "tag" })
135
+ if err != nil {
136
+ return result .WithError (fmt .Errorf ("cannot get installed tags: %w" , err ))
137
+ }
138
+
133
139
// No Elasticsearch asset is created when an Input package is installed through the API.
134
140
// This would require to create a Agent policy and add that input package to the Agent policy.
135
141
// As those input packages could have some required fields, it would also require to add
@@ -151,14 +157,12 @@ func (r *tester) run(ctx context.Context) ([]testrunner.TestResult, error) {
151
157
TestType : TestType ,
152
158
})
153
159
154
- var tr []testrunner. TestResult
155
- if ! findActualAsset (installedAssets , e ) {
160
+ tr , _ := rc . WithSuccess ()
161
+ if ! findActualAsset (installedAssets , installedTags , e ) {
156
162
tr , _ = rc .WithError (testrunner.ErrTestCaseFailed {
157
163
Reason : "could not find expected asset" ,
158
164
Details : fmt .Sprintf ("could not find %s asset \" %s\" . Assets loaded:\n %s" , e .Type , e .ID , formatAssetsAsString (installedAssets )),
159
165
})
160
- } else {
161
- tr , _ = rc .WithSuccess ()
162
166
}
163
167
result := tr [0 ]
164
168
if r .withCoverage && e .SourcePath != "" {
@@ -191,13 +195,28 @@ func (r *tester) TearDown(ctx context.Context) error {
191
195
return nil
192
196
}
193
197
194
- func findActualAsset (actualAssets []packages.Asset , expectedAsset packages.Asset ) bool {
198
+ func findActualAsset (actualAssets []packages.Asset , installedTags []common. MapStr , expectedAsset packages.Asset ) bool {
195
199
for _ , a := range actualAssets {
196
200
if a .Type == expectedAsset .Type && a .ID == expectedAsset .ID {
197
201
return true
198
202
}
199
203
}
200
204
205
+ if expectedAsset .Type == "tag" {
206
+ // If we haven't found the asset, and it is a tag, it could be some of the shared tags defined in tags.yml.
207
+ for _ , tag := range installedTags {
208
+ managed , _ := tag .GetValue ("managed" )
209
+ if managed , ok := managed .(bool ); ! ok || ! managed {
210
+ continue
211
+ }
212
+
213
+ id , _ := tag .GetValue ("id" )
214
+ if id , ok := id .(string ); ok && id == expectedAsset .ID {
215
+ return true
216
+ }
217
+ }
218
+ }
219
+
201
220
return false
202
221
}
203
222
0 commit comments