package grpc

import (
	"testing"
)

func Test_redactSecrets(t *testing.T) {
	type args struct {
		msgJson string
	}
	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "case 1",
			args: args{
				msgJson: `{"cluster_id":"3838954", "user_name":"root", "passwd":"my_shining_passwd"}`,
			},
			want: `{"cluster_id":"3838954","passwd":"***","user_name":"root"}`,
		},
		{
			name: "case 2",
			args: args{
				msgJson: `{"code":150100033, "message":"message: ChangePassword, err: Request fail, 500-failed to change the cluster password alter user root: Error 1105: can not find infra cluster by identifier\n", "details":[{"cluster_id":"3838954", "user_name":"root", "passwd":"my_shining_passwd"}]}`,
			},
			want: `{"code":150100033,"details":[{"cluster_id":"3838954","passwd":"***","user_name":"root"}],"message":"message: ChangePassword, err: Request fail, 500-failed to change the cluster password alter user root: Error 1105: can not find infra cluster by identifier\n"}`,
		},
		{
			name: "case 3",
			args: args{
				msgJson: `{"operator": {
  "Username": "root",
  "AuthMethod": "adf",
  "Credential": "asdfsdf"
},"username":"root","clusterID":10682404926023091512,"newPassword":"aaaa"}
`,
			},
			want: `{"clusterID":10682404926023091512,"newPassword":"***","operator":{"AuthMethod":"adf","Credential":"***","Username":"root"},"username":"root"}`,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := RedactSecrets(tt.args.msgJson); got != tt.want {
				t.Errorf("redactSecrets() = %v, want %v", got, tt.want)
			}
		})
	}
}
