Skip to content

Commit

Permalink
fix: separate DetectSopsYaml function to unhide marshalling errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jolbax authored and hbollon committed Aug 2, 2024
1 parent 15d0780 commit 27fe8c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions helm_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ func (c *HelmWrapper) RunHelm() {
}

var encrypted bool
file, err := ReadAndUnmarshalYaml(filename)
fileData, err := ReadAndUnmarshalYaml(filename)
if err != nil {
c.ExitCode = 1
_ = c.errorf("failed to read file '%s': %s", filename, err)
_ = c.errorf("failed to read or unmarshal file '%s': %s", filename, err)
return
}
encrypted = DetectSopsKey(file)
encrypted = DetectSopsKey(fileData)
if err != nil {
return
}
Expand Down
12 changes: 7 additions & 5 deletions utils_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"testing"
"io/ioutil"
"os"
"io/ioutil"
"os"
"testing"
)

func TestDetectSopsFile(t *testing.T) {
Expand All @@ -18,7 +18,8 @@ func TestDetectSopsFile(t *testing.T) {
tmp.WriteString(`---
secret: hello
`)
res, err := DetectSopsYaml(tmp.Name())
fileData, err := ReadAndUnmarshalYaml(tmp.Name())
res := DetectSopsKey(fileData)
if res != false || err != nil {
t.Errorf("DetectSopsYaml(tmp) = %t, %v; want false, <nil>", res, err)
}
Expand All @@ -36,7 +37,8 @@ sops:
pgp: []
version: 3.6.1
`)
res, err = DetectSopsYaml(tmp.Name())
fileData, err = ReadAndUnmarshalYaml(tmp.Name())
res = DetectSopsKey(fileData)
if res != true || err != nil {
t.Errorf("DetectSopsYaml(tmp) = %t, %v; want true, <nil>", res, err)
}
Expand Down

0 comments on commit 27fe8c4

Please sign in to comment.