mirror of
https://github.com/rancher/steve.git
synced 2025-09-02 07:55:31 +00:00
Partial extension API server store + control over printed columns (#432)
* Checkpoint * Add support for custom columns * Remove old Store and Delegate abstraction * Fix nits and rewording * Remove unused mock file * Update documentation for extension api server * Remove the need for scheme for ConvertListOptions * Rename store to utils * fixup! Remove the need for scheme for ConvertListOptions * Move watch helper to tests * Add convertError at a few places * Ignore misspell on creater * Fix comments and remove unused params * Add convertError to missing error returns * Fix watcher implementation * Document request.UserFrom and request.NamespaceFrom
This commit is contained in:
69
pkg/ext/utils_test.go
Normal file
69
pkg/ext/utils_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package ext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestConvertListOptions(t *testing.T) {
|
||||
internal := &metainternalversion.ListOptions{
|
||||
ResourceVersion: "foo",
|
||||
Watch: true,
|
||||
}
|
||||
expected := &metav1.ListOptions{
|
||||
ResourceVersion: "foo",
|
||||
Watch: true,
|
||||
}
|
||||
got, err := ConvertListOptions(internal)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, got)
|
||||
}
|
||||
|
||||
func TestConvertError(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) {
|
||||
assert.Equal(t, tt.output, convertError(tt.input))
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user