mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-05 04:56:11 +00:00
Enable cache mutation detector in unit tests
Signed-off-by: Monis Khan <mok@vmware.com>
This commit is contained in:
29
internal/controller/controller_test.go
Normal file
29
internal/controller/controller_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
func TestCacheMutationDetectorEnabled(t *testing.T) {
|
||||
// this is a bit of simplistic test to check if we have a real cache mutation detector.
|
||||
// if we actually start mutating an informer cache in this test, the test will almost
|
||||
// always fail because the go race detector will see the mutation.
|
||||
// the cache mutation detector will certainly make certain races more common and thus
|
||||
// easily detected by the race detector, but its real use is against a compiled binary
|
||||
// such as pinniped-server running in a pod - that binary has no race detector at runtime.
|
||||
|
||||
c := cache.NewCacheMutationDetector("test pinniped")
|
||||
|
||||
type isRealCacheMutationDetector interface {
|
||||
CompareObjects() // this is brittle, but this function name has never changed...
|
||||
}
|
||||
|
||||
_, ok := c.(isRealCacheMutationDetector)
|
||||
require.Truef(t, ok, "%T is not a real cache mutation detector", c)
|
||||
}
|
||||
Reference in New Issue
Block a user