Skip to content
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

Fix test data generation #130

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions dev/generator/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -14,6 +18,11 @@ import (
"github.com/elastic/integrations-registry/util"
)

var (
tarGz bool
copy bool
)

const (
packageDirName = "package"
)
Expand All @@ -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, "copy", true, "If packages should be copied over")
flag.BoolVar(&tarGz, "tarGz", true, "If packages should be tar gz")
flag.Parse()

if sourceDir == "" || publicDir == "" {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"title": "Example Integration",
"version": "1.0.0",
"description": "This is the example integration",
"type": "integration",
"categories": [
"logs",
"metrics"
Expand Down
5 changes: 3 additions & 2 deletions docs/api/search-kibana652.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
5 changes: 3 additions & 2 deletions docs/api/search-package-example.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "--")

Expand Down
5 changes: 4 additions & 1 deletion testdata/package/example-0.0.2/index.json
Original file line number Diff line number Diff line change
@@ -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"
],
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion testdata/package/example-0.0.2/manifest.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions testdata/package/example-1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"title": "Example Integration",
"version": "1.0.0",
"description": "This is the example integration",
"type": "integration",
"categories": [
"logs",
"metrics"
Expand Down
2 changes: 2 additions & 0 deletions testdata/package/foo-1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"title": "Foo",
"version": "1.0.0",
"description": "This is the foo integration",
"type": "solution",
"categories": [
"metrics"
],
Expand All @@ -13,6 +14,7 @@
}
},
"assets": [
"/package/foo-1.0.0/index.json",
"/package/foo-1.0.0/manifest.yml"
]
}