Skip to content

Commit

Permalink
chore: adding tests for the removeConflicts function & the Convert2W…
Browse files Browse the repository at this point in the history
…aitBackoff function (#2600)

Signed-off-by: zhaque44 <haque.zubair@gmail.com>
  • Loading branch information
zhaque44 authored May 3, 2023
1 parent 42fc8e4 commit 58d56dd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
42 changes: 42 additions & 0 deletions common/expr/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package expr

import (
"fmt"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -61,3 +62,44 @@ func TestEvalBool(t *testing.T) {
assert.NoError(t, err)
assert.True(t, pass)
}

func TestRemoveConflictingKeys(t *testing.T) {
testCases := []struct {
name string
input map[string]interface{}
output map[string]interface{}
}{
{
name: "remove conflicting keys",
input: map[string]interface{}{
"a.b": 1,
"a": 2,
},
output: map[string]interface{}{
"a.b": 1,
},
},
{
name: "no conflicts",
input: map[string]interface{}{
"a": 1,
"b": 2,
"c.d": 3,
},
output: map[string]interface{}{
"a": 1,
"b": 2,
"c.d": 3,
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := removeConflicts(tc.input)
if !reflect.DeepEqual(result, tc.output) {
t.Errorf("expected %v, but got %v", tc.output, result)
}
})
}
}
21 changes: 21 additions & 0 deletions common/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"

apicommon "github.com/argoproj/argo-events/pkg/apis/common"
)
Expand Down Expand Up @@ -117,3 +118,23 @@ func TestRetryFailure(t *testing.T) {
assert.Contains(t, err.Error(), "after retries")
assert.Contains(t, err.Error(), "this is an error")
}

func TestConvert2WaitBackoff(t *testing.T) {
factor := apicommon.NewAmount("1.0")
jitter := apicommon.NewAmount("1")
duration := apicommon.FromString("1s")
backoff := apicommon.Backoff{
Duration: &duration,
Factor: &factor,
Jitter: &jitter,
Steps: 2,
}
waitBackoff, err := Convert2WaitBackoff(&backoff)
assert.NoError(t, err)
assert.Equal(t, wait.Backoff{
Duration: 1 * time.Second,
Factor: 1.0,
Jitter: 1.0,
Steps: 2,
}, *waitBackoff)
}

0 comments on commit 58d56dd

Please sign in to comment.