Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit tests for ValidIDLength #5520

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ func ValidIDLength(
idLength := len(id)
valid := idLength <= errorLimit
if idLength > warnLimit {
scope.IncCounter(metricsCounter)
if scope != nil {
scope.IncCounter(metricsCounter)
dkrotx marked this conversation as resolved.
Show resolved Hide resolved
}
if logger != nil {
logger.Warn("ID length exceeds limit.",
tag.WorkflowDomainName(domainName),
Expand Down
12 changes: 12 additions & 0 deletions common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"errors"
"fmt"
"github.com/uber/cadence/common/log/tag"
"math/rand"
"strconv"
"sync"
Expand Down Expand Up @@ -422,3 +423,14 @@ func TestAwaitWaitGroup(t *testing.T) {
close(doneC)
})
}

func TestValidIDLength(t *testing.T) {
t.Run("valid id length, no warnings", func(t *testing.T) {
got := ValidIDLength("12345", nil, 7, 10, 0, "", nil, tag.Tag{})
require.True(t, got, "expected true, because id length is 5 and it's less than error limit 10")
})
t.Run("non valid id length", func(t *testing.T) {
got := ValidIDLength("12345", nil, 1, 4, 0, "", nil, tag.Tag{})
dkrotx marked this conversation as resolved.
Show resolved Hide resolved
require.False(t, got, "expected false, because id length is 5 and it's more than error limit 4")
})
}