init bin
This commit is contained in:
34
src/chart/conf.go
Normal file
34
src/chart/conf.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package chart
|
||||
|
||||
import (
|
||||
"os"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type ChartData struct {
|
||||
Name string `yaml:"name"`
|
||||
Chart string `yaml:"chart"`
|
||||
Version string `yaml:"version"`
|
||||
|
||||
Opts string `yaml:"helm_opts"`
|
||||
Values string `yaml:"helm_values"`
|
||||
FileValues string `yaml:"helm_filevalues"`
|
||||
|
||||
}
|
||||
|
||||
type ChartRepoData struct {
|
||||
Name string `yaml:"name"`
|
||||
Repository string `yaml:"repository"`
|
||||
Charts []ChartData `yaml:"charts"`
|
||||
}
|
||||
|
||||
type chartsRepoData struct {
|
||||
Charts []ChartRepoData `yaml:"opencloud"`
|
||||
}
|
||||
|
||||
func FromConfigFile(filename string) ([]ChartRepoData) {
|
||||
yamlFile, _ := os.ReadFile(filename)
|
||||
var data chartsRepoData
|
||||
yaml.Unmarshal(yamlFile, &data)
|
||||
return data.Charts
|
||||
}
|
||||
30
src/chart/conf_test.go
Normal file
30
src/chart/conf_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package chart
|
||||
|
||||
// https://pkg.go.dev/github.com/stretchr/testify/assert
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"path/filepath"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
func TestReadConfChart(t *testing.T){
|
||||
src := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||
|
||||
assert.FileExists(t, src, "FromConfigFile error")
|
||||
|
||||
data := FromConfigFile(src)
|
||||
assert.Equal(t, data[0].Name, "bitnami", "FromConfigFile error")
|
||||
assert.Equal(t, data[0].Repository, "https://charts.bitnami.com/bitnami", "FromConfigFile error")
|
||||
|
||||
wordpress := data[0].Charts[0]
|
||||
assert.Equal(t, wordpress.Name, "wordpress", "FromConfigFile error")
|
||||
assert.Equal(t, wordpress.Chart, "bitnami/wordpress", "FromConfigFile error")
|
||||
assert.Equal(t, wordpress.Version, "23.1.0", "FromConfigFile error")
|
||||
|
||||
phpmyadmin := data[0].Charts[1]
|
||||
assert.Equal(t, phpmyadmin.Name, "phpmyadmin", "FromConfigFile error")
|
||||
assert.Equal(t, phpmyadmin.Chart, "bitnami/phpmyadmin", "FromConfigFile error")
|
||||
assert.Equal(t, phpmyadmin.Version, "17.0.4", "FromConfigFile error")
|
||||
}
|
||||
23
src/chart/main_test.go
Normal file
23
src/chart/main_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package chart
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var TEST_DEST_DIR = "../wrk_chart"
|
||||
var TEST_SRC_DIR = filepath.Join("../../test", "chart")
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
folderPath := TEST_DEST_DIR
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
exitCode := m.Run()
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
Reference in New Issue
Block a user