Skip to content

Commit d896aa7

Browse files
authored
[Tests] Remove calendar, filters, transforms & trained models (#420) (#421)
during xpack preflight
1 parent 2827645 commit d896aa7

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

internal/build/cmd/generate/commands/gentests/generator.go

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,86 @@ func (g *Generator) genXPackSetup() {
501501
defer res.Body.Close()
502502
}
503503
}
504+
505+
{
506+
var r struct {
507+
Transforms []struct {
508+
Id string ` + "`json:\"id\"`" + `
509+
} ` + "`json:\"transforms\"`" + `
510+
}
511+
res, _ := es.TransformGetTransform(es.TransformGetTransform.WithTransformID("_all"))
512+
if res != nil && res.Body != nil {
513+
defer res.Body.Close()
514+
json.NewDecoder(res.Body).Decode(&r)
515+
}
516+
for _, transform := range r.Transforms {
517+
id := transform.Id
518+
res, _ := es.TransformDeleteTransform(id)
519+
if res != nil && res.Body != nil {
520+
defer res.Body.Close()
521+
}
522+
}
523+
}
524+
525+
{
526+
var r struct {
527+
TrainedModelConfigs []struct {
528+
ModelId string ` + "`json:\"model_id\"`" + `
529+
} ` + "`json:\"trained_model_configs\"`" + `
530+
}
531+
res, _ := es.ML.GetTrainedModels(es.ML.GetTrainedModels.WithModelID("_all"))
532+
if res != nil && res.Body != nil {
533+
defer res.Body.Close()
534+
json.NewDecoder(res.Body).Decode(&r)
535+
for _, model := range r.TrainedModelConfigs {
536+
model_id := model.ModelId
537+
res, _ := es.ML.DeleteTrainedModel(model_id)
538+
if res != nil && res.Body != nil {
539+
defer res.Body.Close()
540+
}
541+
}
542+
}
543+
}
544+
545+
{
546+
var r struct {
547+
Filters []struct {
548+
FilterId string ` + "`json:\"filter_id\"`" + `
549+
} ` + "`json:\"filters\"`" + `
550+
}
551+
res, _ := es.ML.GetFilters()
552+
if res != nil && res.Body != nil {
553+
defer res.Body.Close()
554+
json.NewDecoder(res.Body).Decode(&r)
555+
}
556+
for _, filter := range r.Filters {
557+
filter_id := filter.FilterId
558+
res, _ := es.ML.DeleteFilter(filter_id)
559+
if res != nil && res.Body != nil {
560+
defer res.Body.Close()
561+
}
562+
}
563+
}
564+
565+
{
566+
var r struct {
567+
Calendars []struct {
568+
CalendarId string ` + "`json:\"calendar_id\"`" + `
569+
} ` + "`json:\"calendars\"`" + `
570+
}
571+
res, _ := es.ML.GetCalendars()
572+
if res != nil && res.Body != nil {
573+
defer res.Body.Close()
574+
json.NewDecoder(res.Body).Decode(&r)
575+
}
576+
for _, calendar := range r.Calendars {
577+
calendar_id := calendar.CalendarId
578+
res, _ := es.ML.DeleteCalendar(calendar_id)
579+
if res != nil && res.Body != nil {
580+
defer res.Body.Close()
581+
}
582+
}
583+
}
504584
505585
{
506586
var r map[string]interface{}
@@ -557,14 +637,22 @@ func (g *Generator) genXPackSetup() {
557637
}
558638
559639
{
560-
var r map[string]interface{}
640+
var r struct {
641+
Apps map[string]struct {
642+
Read struct {
643+
Metadata struct {
644+
Description string ` + "`json:\"description\"`" + `
645+
Reserved bool ` + "`json:\"_reserved\"`" + `
646+
} ` + "`json:\"metadata\"`" + `
647+
} ` + "`json:\"read\"`" + `
648+
}
649+
}
561650
res, _ = es.Security.GetPrivileges()
562651
if res != nil && res.Body != nil {
563652
defer res.Body.Close()
564653
json.NewDecoder(res.Body).Decode(&r)
565-
for k, v := range r {
566-
reserved, ok := v.(map[string]interface{})["metadata"].(map[string]interface{})["_reserved"].(bool)
567-
if ok && reserved {
654+
for k, v := range r.Apps {
655+
if v.Read.Metadata.Reserved {
568656
continue
569657
}
570658
es.Security.DeletePrivileges(k, "_all")

0 commit comments

Comments
 (0)