From 0a8cab093fd6f4739ef3574d43a5f833f3b0ec80 Mon Sep 17 00:00:00 2001 From: ruflin Date: Tue, 22 Oct 2019 22:10:59 +0200 Subject: [PATCH 1/2] Fix test data generation When updating the generation process of assets, the test packages were not kept up to date. Some refactoring was needed to make it available again. Now it is always run as part of `mage check` so it is run on all tests. Like this, the test packages are also always up-to-date. --- dev/generator/main.go | 27 ++++++++++++++++----- magefile.go | 3 +++ testdata/package/example-0.0.2/index.json | 5 +++- testdata/package/example-0.0.2/manifest.yml | 3 ++- testdata/package/example-1.0.0/index.json | 1 + testdata/package/foo-1.0.0/index.json | 2 ++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/dev/generator/main.go b/dev/generator/main.go index 8992abd35..4473406a6 100644 --- a/dev/generator/main.go +++ b/dev/generator/main.go @@ -1,3 +1,7 @@ +// 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 ( @@ -14,6 +18,11 @@ import ( "github.com/elastic/integrations-registry/util" ) +var ( + tarGz bool + copy bool +) + const ( packageDirName = "package" ) @@ -26,6 +35,8 @@ func main() { flag.StringVar(&sourceDir, "sourceDir", "", "Path to the source packages") flag.StringVar(&publicDir, "publicDir", "", "Path to the public directory ") + flag.BoolVar(©, "copy", true, "If packages should be copied over") + flag.BoolVar(&tarGz, "tarGz", true, "If packages should be tar gz") flag.Parse() if sourceDir == "" || publicDir == "" { @@ -75,9 +86,11 @@ func BuildPackages(sourceDir, packagesPath string) error { continue } - err := CopyPackage(sourceDir+"/"+packageName, packagesPath) - if err != nil { - return err + if copy { + err := CopyPackage(sourceDir+"/"+packageName, packagesPath) + if err != nil { + return err + } } p, err := util.NewPackage(packagesPath, packageName) @@ -106,9 +119,11 @@ func buildPackage(packagesBasePath string, p util.Package) error { } defer os.Chdir(currentPath) - err = sh.RunV("tar", "cvzf", p.GetPath()+".tar.gz", filepath.Base(p.GetPath())+"/") - if err != nil { - return fmt.Errorf("Error creating package: %s: %s", p.GetPath(), err) + if tarGz { + err = sh.RunV("tar", "cvzf", p.GetPath()+".tar.gz", filepath.Base(p.GetPath())+"/") + if err != nil { + return fmt.Errorf("Error creating package: %s: %s", p.GetPath(), err) + } } // Checks if the package is valid diff --git a/magefile.go b/magefile.go index ab3d74794..af611fdc9 100644 --- a/magefile.go +++ b/magefile.go @@ -74,6 +74,9 @@ func writeJsonFile(v interface{}, path string) error { func Check() error { Format() + // Regenerates test data to make sure it stays the same + sh.RunV("go", "run", "./dev/generator/", "-sourceDir=testdata/package", "-publicDir=testdata", "-copy=false", "-tarGz=false") + sh.RunV("git", "update-index", "--refresh") sh.RunV("git", "diff-index", "--exit-code", "HEAD", "--") diff --git a/testdata/package/example-0.0.2/index.json b/testdata/package/example-0.0.2/index.json index babd4111b..1c1461798 100644 --- a/testdata/package/example-0.0.2/index.json +++ b/testdata/package/example-0.0.2/index.json @@ -1,7 +1,9 @@ { "name": "example", - "version": "0.0.5", + "title": "Example", + "version": "0.0.2", "description": "This is the example integration.", + "type": "integration", "categories": [ "logs" ], @@ -23,6 +25,7 @@ "/package/example-0.0.2/elasticsearch/ingest-pipeline/pipeline-tcp.json", "/package/example-0.0.2/kibana/dashboard/0c610510-5cbd-11e9-8477-077ec9664dbd.json", "/package/example-0.0.2/kibana/index-pattern/filebeat-*.json", + "/package/example-0.0.2/kibana/infrastructure-ui-source/default.json", "/package/example-0.0.2/kibana/visualization/0a994af0-5c9d-11e9-8477-077ec9664dbd.json", "/package/example-0.0.2/kibana/visualization/36f872a0-5c03-11e9-85b4-19d0072eb4f2.json", "/package/example-0.0.2/kibana/visualization/38f96190-5c99-11e9-8477-077ec9664dbd.json", diff --git a/testdata/package/example-0.0.2/manifest.yml b/testdata/package/example-0.0.2/manifest.yml index 68942992b..815d58474 100644 --- a/testdata/package/example-0.0.2/manifest.yml +++ b/testdata/package/example-0.0.2/manifest.yml @@ -1,6 +1,7 @@ name: example +title: Example description: This is the example integration. -version: 0.0.5 +version: 0.0.2 categories: ["logs"] requirement: diff --git a/testdata/package/example-1.0.0/index.json b/testdata/package/example-1.0.0/index.json index 0d986abbb..6dd31ff63 100644 --- a/testdata/package/example-1.0.0/index.json +++ b/testdata/package/example-1.0.0/index.json @@ -3,6 +3,7 @@ "title": "Example Integration", "version": "1.0.0", "description": "This is the example integration", + "type": "integration", "categories": [ "logs", "metrics" diff --git a/testdata/package/foo-1.0.0/index.json b/testdata/package/foo-1.0.0/index.json index 49d9db476..1fadf48dd 100644 --- a/testdata/package/foo-1.0.0/index.json +++ b/testdata/package/foo-1.0.0/index.json @@ -3,6 +3,7 @@ "title": "Foo", "version": "1.0.0", "description": "This is the foo integration", + "type": "solution", "categories": [ "metrics" ], @@ -13,6 +14,7 @@ } }, "assets": [ + "/package/foo-1.0.0/index.json", "/package/foo-1.0.0/manifest.yml" ] } \ No newline at end of file From fb20f9a3933ce02b9dc7737e74ff7505a6a2f404 Mon Sep 17 00:00:00 2001 From: ruflin Date: Tue, 22 Oct 2019 22:31:07 +0200 Subject: [PATCH 2/2] update generated file --- docs/api/package.json | 1 + docs/api/search-kibana652.json | 5 +++-- docs/api/search-package-example.json | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/api/package.json b/docs/api/package.json index 0d986abbb..6dd31ff63 100644 --- a/docs/api/package.json +++ b/docs/api/package.json @@ -3,6 +3,7 @@ "title": "Example Integration", "version": "1.0.0", "description": "This is the example integration", + "type": "integration", "categories": [ "logs", "metrics" diff --git a/docs/api/search-kibana652.json b/docs/api/search-kibana652.json index 7c719db5c..85348003f 100644 --- a/docs/api/search-kibana652.json +++ b/docs/api/search-kibana652.json @@ -1,9 +1,10 @@ [ { "description": "This is the example integration.", - "download": "/package/example-0.0.5.tar.gz", + "download": "/package/example-0.0.2.tar.gz", "name": "example", + "title": "Example", "type": "integration", - "version": "0.0.5" + "version": "0.0.2" } ] \ No newline at end of file diff --git a/docs/api/search-package-example.json b/docs/api/search-package-example.json index bbc0a5a90..9e4da2f73 100644 --- a/docs/api/search-package-example.json +++ b/docs/api/search-package-example.json @@ -1,10 +1,11 @@ [ { "description": "This is the example integration.", - "download": "/package/example-0.0.5.tar.gz", + "download": "/package/example-0.0.2.tar.gz", "name": "example", + "title": "Example", "type": "integration", - "version": "0.0.5" + "version": "0.0.2" }, { "description": "This is the example integration",