pomerium/pkg/contextutil/contextutil_test.go
dependabot[bot] ec495bb682
chore(deps): bump github.com/golangci/golangci-lint from 1.48.0 to 1.50.0 (#3667)
* chore(deps): bump github.com/golangci/golangci-lint

Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.48.0 to 1.50.0.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.48.0...v1.50.0)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* lint

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
2022-10-19 09:36:59 -06:00

38 lines
888 B
Go

package contextutil
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMerge(t *testing.T) {
t.Run("value", func(t *testing.T) {
type contextKey string
k1 := contextKey("key1")
k2 := contextKey("key2")
ctx1 := context.WithValue(context.Background(), k1, "value1")
ctx2 := context.WithValue(context.Background(), k2, "value2")
ctx3, _ := Merge(ctx1, ctx2)
assert.Equal(t, "value1", ctx3.Value(k1))
assert.Equal(t, "value2", ctx3.Value(k2))
})
t.Run("cancel", func(t *testing.T) {
ctx1, cancel1 := context.WithCancel(context.Background())
defer cancel1()
ctx2, cancel2 := context.WithCancel(context.Background())
ctx3, _ := Merge(ctx1, ctx2)
cancel2()
assert.Eventually(t, func() bool {
select {
case <-ctx3.Done():
return true
default:
return false
}
}, time.Second, time.Millisecond*100)
})
}