1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Use install pkg in CLI

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan
2020-10-08 12:30:43 +03:00
parent c4d3fa7a48
commit 5672646278
4 changed files with 73 additions and 304 deletions

View File

@@ -28,13 +28,13 @@ import (
// Generate returns the install manifests as a multi-doc YAML.
// The manifests are built from a GitHub release or from a
// Kustomize overlay if the supplied Options.BaseURL is a local path.
func Generate(options Options) (string, error) {
func Generate(options Options) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), options.Timeout)
defer cancel()
tmpDir, err := ioutil.TempDir("", options.Namespace)
if err != nil {
return "", fmt.Errorf("temp dir error: %w", err)
return nil, fmt.Errorf("temp dir error: %w", err)
}
defer os.RemoveAll(tmpDir)
@@ -42,26 +42,26 @@ func Generate(options Options) (string, error) {
if !strings.HasPrefix(options.BaseURL, "http") {
if err := build(options.BaseURL, output); err != nil {
return "", err
return nil, err
}
} else {
if err := fetch(ctx, options.BaseURL, options.Version, tmpDir); err != nil {
return "", err
return nil, err
}
if err := generate(tmpDir, options); err != nil {
return "", err
return nil, err
}
if err := build(tmpDir, output); err != nil {
return "", err
return nil, err
}
}
content, err := ioutil.ReadFile(output)
if err != nil {
return "", err
return nil, err
}
return string(content), nil
return content, nil
}

View File

@@ -31,10 +31,10 @@ func TestGenerate(t *testing.T) {
for _, component := range opts.Components {
img := fmt.Sprintf("%s/%s", opts.Registry, component)
if !strings.Contains(output, img) {
if !strings.Contains(string(output), img) {
t.Errorf("component image '%s' not found", img)
}
}
fmt.Println(output)
fmt.Println(string(output))
}