Unified Storage: Adds pruner to kv backend (#110549)
* WIP adding pruner to kv store impl * pruner only keeps 20 most recent versions * ignore grafana-kv-data folder * extracts some stuff to pruner.go file. Adds tests. Adds kvBackendOptions. * update logging, comments, exports kvbackendoptions fields * update nooppruner ref * fixes field casing in test * fix test * linter fixes * remove comment * make KvStorageBackend private * Adds pruner key validation and tests. Fixes broken tests. * update error message when validating pruner key
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package resource
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPrunerValidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
key PruningKey
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "valid key",
|
||||
key: PruningKey{
|
||||
Namespace: "default",
|
||||
Group: "apps",
|
||||
Resource: "deployments",
|
||||
Name: "my-deployment",
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "missing namespace",
|
||||
key: PruningKey{
|
||||
Group: "apps",
|
||||
Resource: "deployments",
|
||||
Name: "my-deployment",
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "missing group",
|
||||
key: PruningKey{
|
||||
Namespace: "default",
|
||||
Resource: "deployments",
|
||||
Name: "my-deployment",
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "missing resource",
|
||||
key: PruningKey{
|
||||
Namespace: "default",
|
||||
Group: "apps",
|
||||
Name: "my-deployment",
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "missing name",
|
||||
key: PruningKey{
|
||||
Namespace: "default",
|
||||
Group: "apps",
|
||||
Resource: "deployments",
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := tt.key.Validate()
|
||||
if result != tt.expected {
|
||||
t.Errorf("expected %v, got %v", tt.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user