generated from LinuxSuRen/.github
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate SonarQube configuration from kubesphere-config into devops-co…
…nfig (#245) * Migrate SonarQube configuration from kubesphere-config into devops-config Signed-off-by: John Niang <[email protected]> * Rename mergeMap to patchKubeSphereConfig using json-patch library Signed-off-by: John Niang <[email protected]>
- Loading branch information
Showing
3 changed files
with
257 additions
and
42 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package config | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_patchKubeSphereConfig(t *testing.T) { | ||
type args struct { | ||
kubeSphereConfig map[string]interface{} | ||
patch map[string]interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]interface{} | ||
wantErr bool | ||
}{{ | ||
name: "Patch non-exist fields recursively", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
}, | ||
}, | ||
patch: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"password": "fake password", | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
"password": "fake password", | ||
}, | ||
}, | ||
}, { | ||
name: "Patch non-exist field", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
}, | ||
}, | ||
patch: map[string]interface{}{ | ||
"sonarQube": map[string]interface{}{ | ||
"token": "fake token", | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
}, | ||
"sonarQube": map[string]interface{}{ | ||
"token": "fake token", | ||
}, | ||
}, | ||
}, { | ||
name: "Patch existing field", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
}, | ||
"sonarQube": map[string]interface{}{ | ||
"token": "fake token", | ||
}, | ||
}, | ||
patch: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": false, | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": false, | ||
}, | ||
"sonarQube": map[string]interface{}{ | ||
"token": "fake token", | ||
}, | ||
}, | ||
}, { | ||
name: "Report an error if patch is nil", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
}, | ||
}, | ||
patch: nil, | ||
}, | ||
wantErr: true, | ||
}, { | ||
name: "Report an error if KubeSphereConfig is nil", | ||
args: args{ | ||
kubeSphereConfig: nil, | ||
patch: map[string]interface{}{}, | ||
}, | ||
wantErr: true, | ||
}, { | ||
name: "Patch with different type", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
}, | ||
}, | ||
patch: map[string]interface{}{ | ||
"devops": "awesome", | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"devops": "awesome", | ||
}, | ||
}, { | ||
name: "Patch with map[string]string type", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
"password": "fake password", | ||
}, | ||
}, | ||
patch: map[string]interface{}{ | ||
"devops": map[string]string{ | ||
"password": "patch password", | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
"password": "patch password", | ||
}, | ||
}, | ||
}, { | ||
name: "Patch without map[string]interface{}", | ||
args: args{ | ||
kubeSphereConfig: map[string]interface{}{ | ||
"devops": map[string]bool{ | ||
"enabled": true, | ||
}, | ||
}, | ||
patch: map[string]interface{}{ | ||
"devops": map[string]bool{ | ||
"disabled": false, | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"devops": map[string]interface{}{ | ||
"enabled": true, | ||
"disabled": false, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := patchKubeSphereConfig(tt.args.kubeSphereConfig, tt.args.patch) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("patchKubeSphereConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("patchKubeSphereConfig() = %+v, want = %+v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |