Validation: Move validation into apimachinery package (#111736)

This commit is contained in:
Ryan McKinley
2025-09-30 12:59:33 +00:00
committed by GitHub
parent d8fd872ad3
commit cfbf64c3fd
13 changed files with 379 additions and 133 deletions
+13 -3
View File
@@ -3,6 +3,7 @@ package apistore
import (
"context"
"math/rand/v2"
"strings"
"testing"
"time"
@@ -35,6 +36,7 @@ func TestPrepareObjectForStorage(t *testing.T) {
opts: StorageOptions{
EnableFolderSupport: true,
LargeObjectSupport: nil,
MaximumNameLength: 100,
},
}
@@ -49,10 +51,18 @@ func TestPrepareObjectForStorage(t *testing.T) {
})
t.Run("Error on missing name", func(t *testing.T) {
dashboard := dashv1.Dashboard{}
_, err := s.prepareObjectForStorage(ctx, dashboard.DeepCopyObject())
dashboard := &dashv1.Dashboard{}
_, err := s.prepareObjectForStorage(ctx, dashboard)
require.Error(t, err)
require.Contains(t, err.Error(), "missing name")
require.ErrorContains(t, err, "missing name")
})
t.Run("name is too long", func(t *testing.T) {
dashboard := &dashv1.Dashboard{}
dashboard.Name = strings.Repeat("a", 120)
_, err := s.prepareObjectForStorage(ctx, dashboard)
require.Error(t, err)
require.ErrorContains(t, err, "name exceeds maximum length")
})
t.Run("Error on non-empty resource version", func(t *testing.T) {