From 30a1c136dc1bbf7591b8f177c36c83cedcc45a14 Mon Sep 17 00:00:00 2001 From: volodymyrZotov Date: Tue, 25 Oct 2022 18:00:41 +0300 Subject: [PATCH] generate random version each time calling mock onepassword item --- controllers/onepassworditem_controller_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/controllers/onepassworditem_controller_test.go b/controllers/onepassworditem_controller_test.go index 7a1f01d..a7d6df9 100644 --- a/controllers/onepassworditem_controller_test.go +++ b/controllers/onepassworditem_controller_test.go @@ -2,6 +2,8 @@ package controllers import ( "context" + "math/rand" + "time" "github.com/1Password/connect-sdk-go/onepassword" "github.com/1Password/onepassword-operator/pkg/mocks" @@ -24,6 +26,11 @@ const ( iceCream = "freezing blue 20%" ) +func randomInt() int { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(1000) +} + var _ = Describe("OnePasswordItem controller", func() { BeforeEach(func() { // failed test runs that don't clean up leave resources behind. @@ -38,7 +45,7 @@ var _ = Describe("OnePasswordItem controller", func() { for k, v := range item1.Data { item.Fields = append(item.Fields, &onepassword.ItemField{Label: k, Value: v}) } - item.Version = item1.Version + item.Version = randomInt() item.Vault.ID = vaultUUID item.ID = uuid return &item, nil @@ -105,7 +112,7 @@ var _ = Describe("OnePasswordItem controller", func() { for k, v := range newData { item.Fields = append(item.Fields, &onepassword.ItemField{Label: k, Value: v}) } - item.Version = item1.Version + 1 + item.Version = randomInt() item.Vault.ID = vaultUUID item.ID = uuid return &item, nil @@ -185,7 +192,7 @@ var _ = Describe("OnePasswordItem controller", func() { for k, v := range testData { item.Fields = append(item.Fields, &onepassword.ItemField{Label: k, Value: v}) } - item.Version = item1.Version + 1 + item.Version = randomInt() item.Vault.ID = vaultUUID item.ID = uuid return &item, nil