1
0
mirror of https://github.com/rancher/steve.git synced 2025-08-04 07:59:21 +00:00
steve/pkg/ext/delegate_error_test.go

61 lines
1.3 KiB
Go
Raw Normal View History

package ext
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestDelegateError_convertError(t *testing.T) {
tests := []struct {
name string
input error
output error
}{
{
name: "api status error",
input: &apierrors.StatusError{
ErrStatus: metav1.Status{
Code: http.StatusNotFound,
Reason: metav1.StatusReasonNotFound,
},
},
output: &apierrors.StatusError{
ErrStatus: metav1.Status{
Code: http.StatusNotFound,
Reason: metav1.StatusReasonNotFound,
},
},
},
{
name: "generic error",
input: assert.AnError,
output: &apierrors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusInternalServerError,
Reason: metav1.StatusReasonInternalError,
Details: &metav1.StatusDetails{
Causes: []metav1.StatusCause{{Message: assert.AnError.Error()}},
},
Message: fmt.Sprintf("Internal error occurred: %v", assert.AnError),
}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
delegateError := delegateError[*TestType, *TestTypeList]{
inner: &delegate[*TestType, *TestTypeList]{},
}
output := delegateError.convertError(tt.input)
assert.Equal(t, tt.output, output)
})
}
}