Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions constraint/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,9 @@ func (c *Client) RemoveData(ctx context.Context, data interface{}) (*types.Respo

if cacher, ok := h.(handler.Cacher); ok {
cache := cacher.GetCache()

cache.Remove(relPath)
if cache != nil {
cache.Remove(relPath)
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions constraint/pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ import (
"k8s.io/utils/ptr"
)

type nilCacheHandler struct {
*handlertest.Handler
}

func (h *nilCacheHandler) GetCache() handler.Cache {
return nil
}

func TestBackend_NewClient_InvalidTargetName(t *testing.T) {
tcs := []struct {
name string
Expand Down Expand Up @@ -2134,3 +2142,16 @@ func TestClient_RemoveData_Cache(t *testing.T) {
})
}
}

func TestClient_RemoveData_NilCache(t *testing.T) {
h := &nilCacheHandler{
Handler: &handlertest.Handler{},
}

c := clienttest.New(t, client.Targets(h))

_, err := c.RemoveData(context.Background(), &handlertest.Object{Namespace: "foo"})
if err != nil {
t.Fatalf("got RemoveData() error = %v, want nil", err)
}
}
Loading