forked from samber/oops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
41 lines (31 loc) · 916 Bytes
/
utils_test.go
File metadata and controls
41 lines (31 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package oops
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCoalesceOrEmpty(t *testing.T) {
is := assert.New(t)
// Test with non-empty values
result := coalesceOrEmpty("", "test", "another")
is.Equal("test", result)
// Test with all empty values
result2 := coalesceOrEmpty("", "", "")
is.Equal("", result2)
// Test with no values
result3 := coalesceOrEmpty[string]()
is.Equal("", result3)
}
func TestContextValueOrNil(t *testing.T) {
is := assert.New(t)
// Test with context containing value
ctx := context.WithValue(context.Background(), "key", "value") //nolint:staticcheck
result := contextValueOrNil(ctx, "key")
is.Equal("value", result)
// Test with context not containing key
result2 := contextValueOrNil(ctx, "nonexistent")
is.Nil(result2)
// Test with nil context
result3 := contextValueOrNil(nil, "key") //nolint:staticcheck
is.Nil(result3)
}