github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/storage/driver/memory/runtime_state_test.go (about) 1 package memory 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/google/uuid" 8 reconcilerApi "github.com/kyma-incubator/reconciler/pkg/keb" 9 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func Test_runtimeState_GetLatestByRuntimeID(t *testing.T) { 14 // given 15 runtimeStates := NewRuntimeStates() 16 17 olderRuntimeStateID := "older" 18 newerRuntimeStateID := "newer" 19 expectedRuntimeStateID := "expected" 20 fixRuntimeID := "runtime1" 21 22 olderRuntimeState := fixture.FixRuntimeState(olderRuntimeStateID, fixRuntimeID, uuid.NewString()) 23 olderRuntimeState.ClusterSetup = &reconcilerApi.Cluster{RuntimeID: fixRuntimeID} 24 25 newerRuntimeState := fixture.FixRuntimeState(newerRuntimeStateID, fixRuntimeID, uuid.NewString()) 26 newerRuntimeState.ClusterSetup = &reconcilerApi.Cluster{RuntimeID: fixRuntimeID} 27 newerRuntimeState.CreatedAt = newerRuntimeState.CreatedAt.Add(time.Hour * 1) 28 29 expectedRuntimeState := fixture.FixRuntimeState(expectedRuntimeStateID, fixRuntimeID, uuid.NewString()) 30 expectedRuntimeState.ClusterSetup = &reconcilerApi.Cluster{RuntimeID: fixRuntimeID} 31 expectedRuntimeState.CreatedAt = expectedRuntimeState.CreatedAt.Add(time.Hour * 2) 32 33 runtimeStates.Insert(olderRuntimeState) 34 runtimeStates.Insert(expectedRuntimeState) 35 runtimeStates.Insert(newerRuntimeState) 36 37 // when 38 gotRuntimeState, _ := runtimeStates.GetLatestByRuntimeID(fixRuntimeID) 39 40 // then 41 assert.Equal(t, expectedRuntimeState.ID, gotRuntimeState.ID) 42 } 43 44 func Test_runtimeState_GetLatestWithReconcilerInputByRuntimeID(t *testing.T) { 45 // given 46 runtimeStates := NewRuntimeStates() 47 48 olderRuntimeStateID := "older" 49 newestRuntimeStateID := "newest" 50 expectedRuntimeStateID := "expected" 51 fixRuntimeID := "runtime1" 52 53 olderRuntimeState := fixture.FixRuntimeState(olderRuntimeStateID, fixRuntimeID, uuid.NewString()) 54 olderRuntimeState.ClusterSetup = &reconcilerApi.Cluster{RuntimeID: fixRuntimeID} 55 56 newestRuntimeStateWithoutReconcilerInput := fixture.FixRuntimeState(newestRuntimeStateID, fixRuntimeID, uuid.NewString()) 57 newestRuntimeStateWithoutReconcilerInput.CreatedAt = newestRuntimeStateWithoutReconcilerInput.CreatedAt.Add(time.Hour * 2) 58 59 expectedRuntimeState := fixture.FixRuntimeState(expectedRuntimeStateID, fixRuntimeID, uuid.NewString()) 60 expectedRuntimeState.ClusterSetup = &reconcilerApi.Cluster{RuntimeID: fixRuntimeID} 61 expectedRuntimeState.CreatedAt = expectedRuntimeState.CreatedAt.Add(time.Hour * 1) 62 63 runtimeStates.Insert(olderRuntimeState) 64 runtimeStates.Insert(expectedRuntimeState) 65 runtimeStates.Insert(newestRuntimeStateWithoutReconcilerInput) 66 67 // when 68 gotRuntimeState, _ := runtimeStates.GetLatestWithReconcilerInputByRuntimeID(fixRuntimeID) 69 70 // then 71 assert.Equal(t, expectedRuntimeState.ID, gotRuntimeState.ID) 72 }