Don't return nil, nil for API service methods. Add tests for updating w/ wrong version. (#396)
This commit is contained in:
1 parent
1adbe64160
commit
21f5cc274f
20 files changed
+71
-23
No files matched your search
@@ -174,6 +174,12 @@ func TestErrors(t *testing.T) {
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(u)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = accountClient.Update(tc.Context(), u.Item.Id, 73, accounts.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
// Create another resource with the same name.
|
||||
_, apiErr, err = accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName("first"))
|
||||
require.NoError(err)
|
||||
|
||||
@@ -197,6 +197,12 @@ func TestErrors(t *testing.T) {
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(g)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = groupClient.Update(tc.Context(), g.Item.Id, 73, groups.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
// Create another resource with the same name.
|
||||
_, apiErr, err = groupClient.Create(tc.Context(), tt.scopeId, groups.WithName("first"))
|
||||
require.NoError(err)
|
||||
|
||||
@@ -137,6 +137,12 @@ func TestErrors(t *testing.T) {
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(hc)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = pc.Update(tc.Context(), hc.Item.Id, 73, hostcatalogs.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
_, apiErr, err = pc.Create(tc.Context(), "static", proj.GetPublicId(), hostcatalogs.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -155,6 +155,12 @@ func TestErrors(t *testing.T) {
|
||||
require.Nil(apiErr)
|
||||
assert.NotNil(h)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = hClient.Update(tc.Context(), h.Item.Id, 73, hosts.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
_, apiErr, err = hClient.Create(tc.Context(), hc.Item.Id, hosts.WithName("foo"), hosts.WithStaticHostAddress("someaddress"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -200,6 +200,12 @@ func TestErrors(t *testing.T) {
|
||||
require.Nil(apiErr)
|
||||
assert.NotNil(h)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = hClient.Update(tc.Context(), h.Item.Id, 73, hostsets.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
h, apiErr, err = hClient.Create(tc.Context(), hc.Item.Id, hostsets.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -292,6 +292,12 @@ func TestErrors(t *testing.T) {
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(u)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = roleClient.Update(tc.Context(), u.Item.Id, 73, roles.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
// Create another resource with the same name.
|
||||
_, apiErr, err = roleClient.Create(tc.Context(), tt.scopeId, roles.WithName("first"))
|
||||
require.NoError(err)
|
||||
|
||||
@@ -123,6 +123,12 @@ func TestErrors(t *testing.T) {
|
||||
assert.NotNil(createdProj)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = scps.Update(tc.Context(), createdProj.Item.Id, 73, scopes.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
_, apiErr, err = scps.Read(tc.Context(), "p_doesntexis")
|
||||
require.NoError(err)
|
||||
// TODO: Should this be nil instead of just a Project that has no values set
|
||||
|
||||
@@ -170,7 +170,6 @@ func TestCrud(t *testing.T) {
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
}
|
||||
|
||||
// TODO: Get better coverage for expected errors and error formats.
|
||||
func TestSet_Errors(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
tc := controller.NewTestController(t, nil)
|
||||
@@ -187,6 +186,13 @@ func TestSet_Errors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
assert.NotNil(tar)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = tarClient.Update(tc.Context(), tar.Item.Id, 73, targets.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
tar, apiErr, err = tarClient.Create(tc.Context(), "tcp", proj.GetPublicId(), targets.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -134,6 +134,12 @@ func TestErrors(t *testing.T) {
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(u)
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, apiErr, err = userClient.Update(tc.Context(), u.Item.Id, 73, users.WithName("anything"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
// Create another resource with the same name.
|
||||
_, apiErr, err = userClient.Create(tc.Context(), org.GetPublicId(), users.WithName("first"))
|
||||
require.NoError(err)
|
||||
|
||||
Reference in new issue
Block a user