-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding pagination for installation, parameter, and credential list result using skip and limit option #2137
Changes from 1 commit
ebac171
6a99e63
7715769
e003f6a
1954b07
ec77a4c
b1852a2
7f0022e
356e39f
48b6b63
b3fbba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,35 @@ func TestCredentialStorage_CRUD(t *testing.T) { | |
|
||
require.NoError(t, cp.InsertCredentialSet(context.Background(), cs)) | ||
|
||
creds, err := cp.ListCredentialSets(context.Background(), "dev", "", nil) | ||
creds, err := cp.ListCredentialSets(context.Background(), ListOptions{ | ||
Namespace: "dev", | ||
Name: "", | ||
Labels: nil, | ||
Skip: 0, | ||
Limit: 0, | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the nice thing about using an options struct is that you can now omit fields where you aren't changing the default. This allows us to set a better default in the future, and limit how often code has to change when it's about fields that it doesn't care about. Let's remove the labels, skip and limit fields from here and anywhere else that we aren't setting a non-default value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also actually not sure why did I do that either... I think my brain automatically did that since seeing the previous function parameter input that lists out all of the default primitive values so I did that to the struct as well 😂 Fixed! |
||
require.NoError(t, err) | ||
require.Len(t, creds, 1, "expected 1 credential set") | ||
require.Equal(t, cs.Name, creds[0].Name, "expected to retrieve secreks credentials") | ||
require.Equal(t, cs.Namespace, creds[0].Namespace, "expected to retrieve secreks credentials") | ||
require.Equal(t, cs.Name, creds[0].Name, "expected to retrieve sekrets credentials") | ||
carolynvs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.Equal(t, cs.Namespace, creds[0].Namespace, "expected to retrieve sekrets credentials") | ||
|
||
creds, err = cp.ListCredentialSets(context.Background(), "", "", nil) | ||
creds, err = cp.ListCredentialSets(context.Background(), ListOptions{ | ||
Namespace: "", | ||
Name: "", | ||
Labels: nil, | ||
Skip: 0, | ||
Limit: 0, | ||
}) | ||
require.NoError(t, err) | ||
require.Len(t, creds, 0, "expected no global credential sets") | ||
|
||
creds, err = cp.ListCredentialSets(context.Background(), "*", "", nil) | ||
creds, err = cp.ListCredentialSets(context.Background(), ListOptions{ | ||
Namespace: "*", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in this case you can remove all of the fields except namespace. |
||
Name: "", | ||
Labels: nil, | ||
Skip: 0, | ||
Limit: 0, | ||
}) | ||
require.NoError(t, err) | ||
require.Len(t, creds, 1, "expected 1 credential set defined in all namespaces") | ||
|
||
|
@@ -45,9 +63,42 @@ func TestCredentialStorage_CRUD(t *testing.T) { | |
require.NoError(t, err) | ||
assert.Len(t, cs.Credentials, 2) | ||
|
||
cs2 := NewCredentialSet("dev", "sekrets-2", secrets.Strategy{ | ||
Name: "password-2", Source: secrets.Source{ | ||
Key: "secret-2", | ||
Value: "dbPassword-2"}}) | ||
require.NoError(t, cp.InsertCredentialSet(context.Background(), cs2)) | ||
|
||
creds, err = cp.ListCredentialSets(context.Background(), ListOptions{ | ||
Namespace: "dev", | ||
Name: "", | ||
Labels: nil, | ||
Skip: 1, | ||
Limit: 0, | ||
}) | ||
require.NoError(t, err) | ||
require.Len(t, creds, 1, "expected 1 credential set") | ||
require.Equal(t, cs2.Name, creds[0].Name, "expected to retrieve sekrets-2 credentials") | ||
require.Equal(t, cs2.Namespace, creds[0].Namespace, "expected to retrieve sekrets-2 credentials") | ||
|
||
creds, err = cp.ListCredentialSets(context.Background(), ListOptions{ | ||
Namespace: "dev", | ||
Name: "", | ||
Labels: nil, | ||
Skip: 0, | ||
Limit: 1, | ||
}) | ||
require.NoError(t, err) | ||
require.Len(t, creds, 1, "expected 1 credential set") | ||
require.Equal(t, cs.Name, creds[0].Name, "expected to retrieve sekrets credentials") | ||
require.Equal(t, cs.Namespace, creds[0].Namespace, "expected to retrieve sekrets credentials") | ||
|
||
require.NoError(t, cp.RemoveCredentialSet(context.Background(), cs.Namespace, cs.Name)) | ||
require.NoError(t, cp.RemoveCredentialSet(context.Background(), cs2.Namespace, cs2.Name)) | ||
_, err = cp.GetCredentialSet(context.Background(), cs.Namespace, cs.Name) | ||
require.ErrorIs(t, err, ErrNotFound{}) | ||
_, err = cp.GetCredentialSet(context.Background(), cs2.Namespace, cs2.Name) | ||
require.ErrorIs(t, err, ErrNotFound{}) | ||
} | ||
|
||
func TestCredentialStorage_Validate_GoodSources(t *testing.T) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the sort!