Files
tasks/common/masker/masker_test.go
Stephan BehnkeandGitHub c9e360a3fb go fix (#9337)
## What changed?

Integrate Go 1.26's new `go fix` into workflow.

NOTE that the changes caused our linter to fire; a [separate
commit](https://github.com/temporalio/temporal/pull/9337/commits/1b23f787aef370098b35829c4d17dcc06230b4c1)
addresses those.

## Why?

Ensure Go code is standardized/modernized.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2026-02-18 09:12:19 -08:00

77 lines
1.7 KiB
Go

package masker
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMaskStruct(t *testing.T) {
assert := assert.New(t)
type strct struct {
Login string
Password string
}
s1 := strct{
Login: "login",
Password: "password",
}
maskedS1 := MaskStruct(s1, DefaultFieldNames)
assert.Equal("password", s1.Password)
assert.Equal("******", maskedS1.(*strct).Password)
assert.Equal("login", maskedS1.(*strct).Login)
s2 := &strct{
Login: "login",
Password: "password",
}
maskedS2 := MaskStruct(s2, DefaultFieldNames)
assert.Equal("password", s2.Password)
assert.Equal("******", maskedS2.(*strct).Password)
assert.Equal("login", maskedS2.(*strct).Login)
}
func TestMaskStruct_Nil(t *testing.T) {
assert := assert.New(t)
maskedS1 := MaskStruct(nil, DefaultFieldNames)
assert.Nil(maskedS1)
var nilInterface any
maskedS2 := MaskStruct(nilInterface, DefaultFieldNames)
assert.Nil(maskedS2)
var nilInt *int
maskedS3 := MaskStruct(nilInt, DefaultFieldNames)
assert.Nil(maskedS3)
}
func TestMaskYaml(t *testing.T) {
assert := assert.New(t)
yaml := `persistence:
defaultStore: mysql-default
visibilityStore: mysql-visibility
numHistoryShards: 4
datastores:
mysql-default:
sql:
pluginName: "mysql"
databaseName: "temporal"
connectAddr: "127.0.0.1:3306"
connectProtocol: "tcp"
user: "temporal"
password: "secret"`
maskedYaml, err := MaskYaml(yaml, DefaultYAMLFieldNames)
assert.NoError(err)
assert.True(strings.Contains(yaml, "secret"))
assert.False(strings.Contains(maskedYaml, "secret"))
assert.True(strings.Contains(maskedYaml, "******"))
fmt.Println(maskedYaml)
}