Skip to content

Commit

Permalink
Merge pull request #52 from mittwald/fix/policy_id
Browse files Browse the repository at this point in the history
use correct policy id & rename custom error
  • Loading branch information
jkmw authored Aug 25, 2020
2 parents 35a5098 + aa3ab7c commit ea3dc8e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions replication/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (c *RESTClient) TriggerReplicationExecution(ctx context.Context, r *model.R
return &ErrReplicationExecutionNotProvided{}
}

if _, err := c.GetReplicationPolicyByID(ctx, r.ID); err != nil {
return &ErrReplicationExecutionReplicationIDNotFound{}
if _, err := c.GetReplicationPolicyByID(ctx, r.PolicyID); err != nil {
return &ErrReplicationExecutionReplicationPolicyIDNotFound{}
}

_, err := c.Client.Products.PostReplicationExecutions(
Expand All @@ -198,8 +198,8 @@ func (c *RESTClient) TriggerReplicationExecution(ctx context.Context, r *model.R
// Specifying the property "policy_id" will return executions of the specified policy.
func (c *RESTClient) GetReplicationExecutions(ctx context.Context,
r *model.ReplicationExecution) ([]*model.ReplicationExecution, error) {
if _, err := c.GetReplicationPolicyByID(ctx, r.ID); err != nil {
return nil, &ErrReplicationExecutionReplicationIDNotFound{}
if _, err := c.GetReplicationPolicyByID(ctx, r.PolicyID); err != nil {
return nil, &ErrReplicationExecutionReplicationPolicyIDNotFound{}
}

resp, err := c.Client.Products.GetReplicationExecutions(
Expand All @@ -219,7 +219,7 @@ func (c *RESTClient) GetReplicationExecutions(ctx context.Context,
func (c *RESTClient) GetReplicationExecutionsByID(ctx context.Context,
id int64) (*model.ReplicationExecution, error) {
if _, err := c.GetReplicationPolicyByID(ctx, id); err != nil {
return nil, &ErrReplicationExecutionReplicationIDNotFound{}
return nil, &ErrReplicationExecutionReplicationPolicyIDNotFound{}
}

resp, err := c.Client.Products.GetReplicationExecutionsID(
Expand Down
10 changes: 5 additions & 5 deletions replication/replication_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const (
ErrReplicationExecutionNotProvidedMsg = "no replication execution provided"

// ErrReplicationExecutionMissingIDMsg describes an error
// caused by a missing replication ID in a replication execution object
ErrReplicationExecutionReplicationIDNotFoundMsg = "no replication found for specified id"
// caused by the replication ID of a replication execution object not being found on the server side
ErrReplicationExecutionReplicationPolicyIDNotFoundMsg = "no replication policy found for specified id"

// ErrReplicationExecutionReplicationIDMismatchMsg describes an error
// caused by an ID mismatch of the desired replication execution and an existing replication
Expand Down Expand Up @@ -133,11 +133,11 @@ func (e *ErrReplicationExecutionNotProvided) Error() string {
return ErrReplicationExecutionNotProvidedMsg
}

type ErrReplicationExecutionReplicationIDNotFound struct{}
type ErrReplicationExecutionReplicationPolicyIDNotFound struct{}

// Error returns the error message.
func (e *ErrReplicationExecutionReplicationIDNotFound) Error() string {
return ErrReplicationExecutionReplicationIDNotFoundMsg
func (e *ErrReplicationExecutionReplicationPolicyIDNotFound) Error() string {
return ErrReplicationExecutionReplicationPolicyIDNotFoundMsg
}

type ErrReplicationExecutionReplicationIDMismatch struct{}
Expand Down
16 changes: 8 additions & 8 deletions replication/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,12 @@ func TestRESTClient_GetReplicationExecutions_ErrReplicationExecutionReplicationI
ID: replication.ID,
Context: ctx,
}, mock.AnythingOfType("runtime.ClientAuthInfoWriterFunc")).Return(
nil, &ErrReplicationExecutionReplicationIDNotFound{})
nil, &ErrReplicationExecutionReplicationPolicyIDNotFound{})

_, err := cl.GetReplicationExecutions(ctx, replExec)

if assert.Error(t, err) {
assert.IsType(t, &ErrReplicationExecutionReplicationIDNotFound{}, err)
assert.IsType(t, &ErrReplicationExecutionReplicationPolicyIDNotFound{}, err)
}

p.AssertExpectations(t)
Expand Down Expand Up @@ -653,7 +653,7 @@ func TestRESTClient_GetReplicationExecutions_ReplicationIDNotFound(t *testing.T)
_, err := cl.GetReplicationExecutions(ctx, replicationExecution)

if assert.Error(t, err) {
assert.IsType(t, &ErrReplicationExecutionReplicationIDNotFound{}, err)
assert.IsType(t, &ErrReplicationExecutionReplicationPolicyIDNotFound{}, err)
}

p.AssertExpectations(t)
Expand All @@ -670,11 +670,11 @@ func TestRESTClient_TriggerReplicationExecution_ReplicationIDNotFound(t *testing
ID: replExec.ID,
Context: ctx,
}, mock.AnythingOfType("runtime.ClientAuthInfoWriterFunc")).Return(
nil, &ErrReplicationExecutionReplicationIDNotFound{})
nil, &ErrReplicationExecutionReplicationPolicyIDNotFound{})

err := cl.TriggerReplicationExecution(ctx, replExec)
if assert.Error(t, err) {
assert.IsType(t, &ErrReplicationExecutionReplicationIDNotFound{}, err)
assert.IsType(t, &ErrReplicationExecutionReplicationPolicyIDNotFound{}, err)
}

p.AssertExpectations(t)
Expand Down Expand Up @@ -819,7 +819,7 @@ func TestRESTClient_GetReplicationExecutionsByID_ErrReplicationExecutionReplicat
_, err := cl.GetReplicationExecutionsByID(ctx, replExec.ID)

if assert.Error(t, err) {
assert.IsType(t, &ErrReplicationExecutionReplicationIDNotFound{}, err)
assert.IsType(t, &ErrReplicationExecutionReplicationPolicyIDNotFound{}, err)
}

p.AssertExpectations(t)
Expand Down Expand Up @@ -866,9 +866,9 @@ func TestErrReplicationExecutionReplicationIDMismatch_Error(t *testing.T) {
}

func TestErrReplicationExecutionReplicationIDNotFound_Error(t *testing.T) {
var e ErrReplicationExecutionReplicationIDNotFound
var e ErrReplicationExecutionReplicationPolicyIDNotFound

assert.Equal(t, ErrReplicationExecutionReplicationIDNotFoundMsg, e.Error())
assert.Equal(t, ErrReplicationExecutionReplicationPolicyIDNotFoundMsg, e.Error())
}

func TestErrReplicationIllegalIDFormat_Error(t *testing.T) {
Expand Down

0 comments on commit ea3dc8e

Please sign in to comment.