Skip to content

Commit

Permalink
Export LoadFrom
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Dec 12, 2023
1 parent 8d3d6a1 commit 8114e6d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/helm/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ func Load(yamlPath string) (ValuesMap, error) {
return values, nil
}

// LoadFrom loads a values.yaml snippet from memory and
// returns a ValuesMap with the keys and values from the YAML
func LoadFrom(yamlText string) (ValuesMap, error) {

values := ValuesMap{}

if err := yaml.Unmarshal([]byte(yamlText), &values); err != nil {
return nil, fmt.Errorf("unable to parse %s, error: %s", yamlText, err)
}

return values, nil
}

// ReplaceValuesInHelmValuesFile takes a values.yaml file and replaces values in it with the values provided in the map
// and returns the updated values.yaml file as a string
func ReplaceValuesInHelmValuesFile(values map[string]string, yamlPath string) (string, error) {
Expand Down
23 changes: 23 additions & 0 deletions pkg/helm/io_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package helm

import (
"testing"
)

func Test_LoadFrom(t *testing.T) {
yamlText := `faas-netes:
image: openfaas/faas-netes:0.1.0
`

imageWant := `openfaas/faas-netes:0.1.0`

values, err := LoadFrom(yamlText)
if err != nil {
t.Fatal(err)
}

imageGot := values["faas-netes"].(ValuesMap)["image"]
if imageGot != imageWant {
t.Fatalf("got %q, want %q", imageGot, imageWant)
}
}

0 comments on commit 8114e6d

Please sign in to comment.