Atlas › Test

TestGetOrSetNew_CreatesNew

Exact test identity: go.temporal.io/server/common/util/TestGetOrSetNew_CreatesNew

Package
go.temporal.io/server/common/util
Suite / test hierarchy
TestGetOrSetNew_CreatesNew
Test
TestGetOrSetNew_CreatesNew
Introduced at
util.go ×1 Frontier kind: Joint frontier
Covered ranges
2
Covered lines
5
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/util/util.go 5 covered LOC · 2 ranges

Open complete file

81 // GetOrSetNew looks up k in m and returns the result. If it's not present, it uses `new` to
82 // allocate an new value type and sets that in the map, then returns it.
83 > func GetOrSetNew[M ~map[K]*V, K comparable, V any](m M, k K) *V { util.go
84 > if v, ok := m[k]; ok {
85 return v
86 }
87 > v := new(V) util.go
88 > m[k] = v
89 > return v
90 }
91