-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit but compilation fails
correct db setup creation upsert redefined unit tests for db passing unit test for db layer all functions covered in-memory covered
- Loading branch information
1 parent
355860e
commit b6114c2
Showing
17 changed files
with
526 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dbmodel | ||
|
||
type SubaccountStateDTO struct { | ||
ID string `json:"id"` | ||
|
||
BetaEnabled string `json:"beta_enabled"` | ||
UsedForProduction string `json:"used_for_production"` | ||
|
||
ModifiedAt int64 `json:"modified_at_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package memory | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/kyma-project/kyma-environment-broker/internal" | ||
) | ||
|
||
type SubaccountStates struct { | ||
mutex sync.Mutex | ||
|
||
subaccountStates map[string]internal.SubaccountState | ||
} | ||
|
||
func NewSubaccountStates() *SubaccountStates { | ||
return &SubaccountStates{ | ||
subaccountStates: make(map[string]internal.SubaccountState, 0), | ||
} | ||
} | ||
|
||
func (s *SubaccountStates) DeleteState(subaccountID string) error { | ||
s.mutex.Lock() | ||
defer s.mutex.Unlock() | ||
delete(s.subaccountStates, subaccountID) | ||
|
||
return nil | ||
} | ||
|
||
func (s *SubaccountStates) UpsertState(subaccountState internal.SubaccountState) error { | ||
s.mutex.Lock() | ||
defer s.mutex.Unlock() | ||
|
||
s.subaccountStates[subaccountState.ID] = subaccountState | ||
|
||
return nil | ||
} | ||
|
||
func (s *SubaccountStates) ListStates() ([]internal.SubaccountState, error) { | ||
s.mutex.Lock() | ||
defer s.mutex.Unlock() | ||
|
||
var states []internal.SubaccountState | ||
|
||
//convert map to slice | ||
for _, state := range s.subaccountStates { | ||
states = append(states, state) | ||
} | ||
|
||
return states, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package memory | ||
|
||
import ( | ||
"github.com/kyma-project/kyma-environment-broker/internal" | ||
Check failure on line 4 in internal/storage/driver/memory/subaccount_state_test.go GitHub Actions / run-go-linter
|
||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
subaccountID1 = "subaccountID1" | ||
subaccountID2 = "subaccountID2" | ||
) | ||
|
||
var ( | ||
givenSubaccount1State1 = internal.SubaccountState{ | ||
ID: subaccountID1, | ||
BetaEnabled: "true", | ||
UsedForProduction: "NOT_SET", | ||
ModifiedAt: 10, | ||
} | ||
|
||
givenSubaccount1State2 = internal.SubaccountState{ | ||
ID: subaccountID1, | ||
BetaEnabled: "false", | ||
UsedForProduction: "NOT_SET", | ||
ModifiedAt: 54, | ||
} | ||
givenSubaccount2State3 = internal.SubaccountState{ | ||
ID: subaccountID2, | ||
BetaEnabled: "true", | ||
UsedForProduction: "USED_FOR_PRODUCTION", | ||
ModifiedAt: 108, | ||
} | ||
) | ||
|
||
func TestSubaccountState(t *testing.T) { | ||
subaccountStates := NewSubaccountStates() | ||
|
||
t.Run("should insert and fetch state", func(t *testing.T) { | ||
|
||
err := subaccountStates.UpsertState(givenSubaccount1State1) | ||
require.NoError(t, err) | ||
|
||
actualStates, err := subaccountStates.ListStates() | ||
require.NoError(t, err) | ||
assert.Len(t, actualStates, 1) | ||
assert.Equal(t, "true", actualStates[0].BetaEnabled) | ||
assert.Equal(t, "NOT_SET", actualStates[0].UsedForProduction) | ||
}) | ||
|
||
t.Run("should update subaccount state and then fetch it", func(t *testing.T) { | ||
|
||
err := subaccountStates.UpsertState(givenSubaccount1State2) | ||
|
||
require.NoError(t, err) | ||
actualStates, err := subaccountStates.ListStates() | ||
require.NoError(t, err) | ||
assert.Len(t, actualStates, 1) | ||
assert.Equal(t, "false", actualStates[0].BetaEnabled) | ||
assert.Equal(t, "NOT_SET", actualStates[0].UsedForProduction) | ||
}) | ||
|
||
t.Run("insert second subaccount state and fetch two states", func(t *testing.T) { | ||
|
||
err := subaccountStates.UpsertState(givenSubaccount2State3) | ||
|
||
require.NoError(t, err) | ||
actualStates, err := subaccountStates.ListStates() | ||
require.NoError(t, err) | ||
assert.Len(t, actualStates, 2) | ||
expectedStates := []internal.SubaccountState{givenSubaccount1State2, givenSubaccount2State3} | ||
|
||
for _, expectedState := range expectedStates { | ||
assert.Contains(t, actualStates, expectedState) | ||
|
||
} | ||
}) | ||
|
||
t.Run("delete second subaccount state and fetch one state", func(t *testing.T) { | ||
|
||
err := subaccountStates.DeleteState(subaccountID2) | ||
|
||
require.NoError(t, err) | ||
actualStates, err := subaccountStates.ListStates() | ||
require.NoError(t, err) | ||
assert.Equal(t, givenSubaccount1State2, actualStates[0]) | ||
assert.Len(t, actualStates, 1) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.