feat(refacto): move everything in internal package
This allows to install katenary with `go install` and to clean up the project folder.
This commit is contained in:
80
internal/generator/tools_test.go
Normal file
80
internal/generator/tools_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/katenary/katenary/internal/parser"
|
||||
)
|
||||
|
||||
const unmarshalError = "Failed to unmarshal the output: %s"
|
||||
|
||||
func setup(content string) string {
|
||||
// write the _compose_file in temporary directory
|
||||
tmpDir, err := os.MkdirTemp("", "katenary")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.WriteFile(tmpDir+"/compose.yml", []byte(content), 0o644)
|
||||
return tmpDir
|
||||
}
|
||||
|
||||
func teardown(tmpDir string) {
|
||||
// remove the temporary directory
|
||||
log.Println("Removing temporary directory: ", tmpDir)
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func internalCompileTest(t *testing.T, options ...string) string {
|
||||
_, err := parser.Parse(nil, nil, "compose.yml")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse the project: %s", err)
|
||||
}
|
||||
|
||||
force := false
|
||||
outputDir := "./chart"
|
||||
profiles := make([]string, 0)
|
||||
helmdepUpdate := true
|
||||
var appVersion *string
|
||||
chartVersion := "0.1.0"
|
||||
convertOptions := ConvertOptions{
|
||||
Force: force,
|
||||
OutputDir: outputDir,
|
||||
Profiles: profiles,
|
||||
HelmUpdate: helmdepUpdate,
|
||||
AppVersion: appVersion,
|
||||
ChartVersion: chartVersion,
|
||||
}
|
||||
if err := Convert(convertOptions, "compose.yml"); err != nil {
|
||||
log.Printf("Failed to convert: %s", err)
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
// launch helm lint to check the generated chart
|
||||
if helmLint(convertOptions) != nil {
|
||||
t.Errorf("Failed to lint the generated chart")
|
||||
}
|
||||
// try with helm template
|
||||
var output string
|
||||
if output, err = helmTemplate(convertOptions, options...); err != nil {
|
||||
t.Errorf("Failed to template the generated chart")
|
||||
t.Fatalf("Output %s", output)
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func helmTemplate(options ConvertOptions, arguments ...string) (string, error) {
|
||||
args := []string{"template", options.OutputDir}
|
||||
args = append(args, arguments...)
|
||||
|
||||
cmd := exec.Command("helm", args...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return string(output), err
|
||||
}
|
||||
return string(output), nil
|
||||
}
|
Reference in New Issue
Block a user