Skip to content

Commit

Permalink
#81 fix bug while serializing sensitive config diff
Browse files Browse the repository at this point in the history
Sensitive Config diff was only serialized if there also was normal dogu config diff
  • Loading branch information
alexander-dammeier committed Nov 5, 2024
1 parent 62fae7e commit 0a3d14f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/adapter/kubernetes/blueprintcr/v1/stateDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ConvertToStateDiffDTO(domainModel domain.StateDiff) StateDiff {
var doguConfigDiffByDogu map[common.SimpleDoguName]DoguConfigDiff
var sensitiveDoguConfigDiff map[common.SimpleDoguName]SensitiveDoguConfigDiff

if len(domainModel.DoguConfigDiffs) != 0 {
if len(domainModel.DoguConfigDiffs) != 0 || len(domainModel.SensitiveDoguConfigDiffs) != 0 {
combinedConfigDiffs = make(map[string]CombinedDoguConfigDiff)
for doguName, doguConfigDiff := range domainModel.DoguConfigDiffs {
doguConfigDiffByDogu = make(map[common.SimpleDoguName]DoguConfigDiff)
Expand Down
72 changes: 70 additions & 2 deletions pkg/adapter/kubernetes/blueprintcr/v1/stateDiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var (
testVersionLow = semver.MustParse(testVersionLowRaw)
testVersionHighRaw = "2.3.4"
testVersionHigh = semver.MustParse(testVersionHighRaw)
testDogu = common.SimpleDoguName("testDogu")
testDoguKey1 = common.DoguConfigKey{DoguName: testDogu, Key: "key1"}
)

func TestConvertToDTO(t *testing.T) {
Expand Down Expand Up @@ -554,7 +556,8 @@ func TestConvertToDomainModel(t *testing.T) {
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
return assert.NoError(t, err)
},
}, {
},
{
name: "succeed for multiple component diffs",
dto: StateDiff{
ComponentDiffs: map[string]ComponentDiff{
Expand Down Expand Up @@ -588,7 +591,8 @@ func TestConvertToDomainModel(t *testing.T) {
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
return assert.NoError(t, err)
},
}, {
},
{
name: "fail for multiple component diffs",
dto: StateDiff{
ComponentDiffs: map[string]ComponentDiff{
Expand Down Expand Up @@ -636,3 +640,67 @@ func TestConvertToDomainModel(t *testing.T) {
})
}
}

func TestConvertToStateDiffDTO(t *testing.T) {

tests := []struct {
name string
model domain.StateDiff
want StateDiff
}{
{
name: "ok",
model: domain.StateDiff{
DoguDiffs: nil,
ComponentDiffs: nil,
DoguConfigDiffs: map[common.SimpleDoguName]domain.DoguConfigDiffs{},
SensitiveDoguConfigDiffs: map[common.SimpleDoguName]domain.SensitiveDoguConfigDiffs{
testDogu: {
{
Key: testDoguKey1,
Actual: domain.DoguConfigValueState{
Value: "123",
Exists: true,
},
Expected: domain.DoguConfigValueState{
Value: "123",
Exists: true,
},
NeededAction: domain.ConfigActionSet,
},
},
},
GlobalConfigDiffs: nil,
},
want: StateDiff{
DoguDiffs: map[string]DoguDiff{},
ComponentDiffs: map[string]ComponentDiff{},
DoguConfigDiffs: map[string]CombinedDoguConfigDiff{
testDogu.String(): {
DoguConfigDiff: DoguConfigDiff(nil),
SensitiveDoguConfigDiff: SensitiveDoguConfigDiff{
DoguConfigEntryDiff{
Key: testDoguKey1.Key.String(),
Actual: DoguConfigValueState{
Value: "123",
Exists: true,
},
Expected: DoguConfigValueState{
Value: "123",
Exists: true,
},
NeededAction: ConfigAction("set"),
},
},
},
},
GlobalConfigDiff: nil,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, ConvertToStateDiffDTO(tt.model), "ConvertToStateDiffDTO(%v)", tt.model)
})
}
}

0 comments on commit 0a3d14f

Please sign in to comment.