Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions chartutil/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (e *ErrValuesReference) Error() string {
if key := e.Key; key != "" {
b.WriteString(fmt.Sprintf(" with key '%s'", key))
}
reason := e.Reason.Error()
if reason == "" && e.Err == nil {
reason = ErrUnknown.Error()
reason := ErrUnknown.Error()
if e.Reason != nil && e.Reason.Error() != "" {
reason = e.Reason.Error()
}
if e.Err != nil {
reason = e.Err.Error()
Expand Down
34 changes: 34 additions & 0 deletions chartutil/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package chartutil

import (
"context"
"errors"
"testing"

"github.com/go-logr/logr"
Expand All @@ -26,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -406,6 +408,38 @@ func TestReplacePathValue(t *testing.T) {
}
}

func TestErrValuesReferenceErrorNilReason(t *testing.T) {
tests := []struct {
name string
err *ErrValuesReference
want string
}{
{
name: "without wrapped error",
err: &ErrValuesReference{
Name: types.NamespacedName{Namespace: "default", Name: "values"},
},
want: "could not resolve chart values reference 'default/values': unknown error",
},
{
name: "with wrapped error",
err: &ErrValuesReference{
Name: types.NamespacedName{Namespace: "default", Name: "values"},
Err: errors.New("boom"),
},
want: "could not resolve chart values reference 'default/values': boom",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
g.Expect(func() { _ = tt.err.Error() }).ToNot(Panic())
g.Expect(tt.err.Error()).To(Equal(tt.want))
})
}
}

func mockSecret(name string, data map[string][]byte) *corev1.Secret {
return &corev1.Secret{
TypeMeta: metav1.TypeMeta{
Expand Down
Loading