cozystack/pkg/generated/applyconfiguration/utils_test.go
Aleksei Sviridkin 75e25fa977
fix(codegen): add gen_client to update-codegen.sh and regenerate applyconfiguration
The applyconfiguration code referenced testing.TypeConverter from
k8s.io/client-go/testing, which was removed in client-go v0.34.1.

Root cause: hack/update-codegen.sh called gen_helpers and gen_openapi
but not gen_client, so applyconfiguration was never regenerated after
the client-go upgrade.

Changes:
- Fix THIS_PKG from sample-apiserver template leftover to correct
  module path
- Add kube::codegen::gen_client call with --with-applyconfig flag
- Regenerate applyconfiguration (now uses managedfields.TypeConverter)
- Add tests for ForKind and NewTypeConverter functions

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-02-16 23:01:38 +03:00

64 lines
2 KiB
Go

/*
Copyright 2025 The Cozystack Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package applyconfiguration
import (
"testing"
v1alpha1 "github.com/cozystack/cozystack/pkg/apis/apps/v1alpha1"
appsv1alpha1 "github.com/cozystack/cozystack/pkg/generated/applyconfiguration/apps/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func TestForKind_Application(t *testing.T) {
gvk := v1alpha1.SchemeGroupVersion.WithKind("Application")
got := ForKind(gvk)
if got == nil {
t.Fatal("ForKind returned nil for Application GVK")
}
if _, ok := got.(*appsv1alpha1.ApplicationApplyConfiguration); !ok {
t.Fatalf("ForKind returned %T, want *ApplicationApplyConfiguration", got)
}
}
func TestForKind_ApplicationStatus(t *testing.T) {
gvk := v1alpha1.SchemeGroupVersion.WithKind("ApplicationStatus")
got := ForKind(gvk)
if got == nil {
t.Fatal("ForKind returned nil for ApplicationStatus GVK")
}
if _, ok := got.(*appsv1alpha1.ApplicationStatusApplyConfiguration); !ok {
t.Fatalf("ForKind returned %T, want *ApplicationStatusApplyConfiguration", got)
}
}
func TestForKind_Unknown(t *testing.T) {
gvk := schema.GroupVersionKind{Group: "unknown.io", Version: "v1", Kind: "Unknown"}
got := ForKind(gvk)
if got != nil {
t.Fatalf("ForKind returned %T for unknown GVK, want nil", got)
}
}
func TestNewTypeConverter(t *testing.T) {
scheme := runtime.NewScheme()
tc := NewTypeConverter(scheme)
if tc == nil {
t.Fatal("NewTypeConverter returned nil")
}
}