@@ -34,6 +34,7 @@ import (
3434 "k8s.io/client-go/kubernetes/fake"
3535 kubernetesscheme "k8s.io/client-go/kubernetes/scheme"
3636 "k8s.io/client-go/rest"
37+ "k8s.io/kubectl/pkg/describe"
3738)
3839
3940type describeClient struct {
@@ -792,3 +793,82 @@ func Test_describeBuildVolumes(t *testing.T) {
792793 })
793794 }
794795}
796+
797+ func TestTemplateInstanceDescriberNilSecret (t * testing.T ) {
798+ tests := []struct {
799+ name string
800+ templateInstance * templatev1.TemplateInstance
801+ want []string
802+ }{
803+ {
804+ name : "template instance with nil secret" ,
805+ templateInstance : & templatev1.TemplateInstance {
806+ ObjectMeta : metav1.ObjectMeta {
807+ Name : "test-template-instance" ,
808+ Namespace : "test-namespace" ,
809+ },
810+ Spec : templatev1.TemplateInstanceSpec {
811+ Template : templatev1.Template {
812+ ObjectMeta : metav1.ObjectMeta {
813+ Name : "test-template" ,
814+ },
815+ },
816+ Secret : nil ,
817+ },
818+ Status : templatev1.TemplateInstanceStatus {
819+ Conditions : []templatev1.TemplateInstanceCondition {},
820+ Objects : []templatev1.TemplateInstanceObject {},
821+ },
822+ },
823+ want : []string {
824+ "No secret specified for parameters" ,
825+ },
826+ },
827+ {
828+ name : "template instance with secret" ,
829+ templateInstance : & templatev1.TemplateInstance {
830+ ObjectMeta : metav1.ObjectMeta {
831+ Name : "test-template-instance" ,
832+ Namespace : "test-namespace" ,
833+ },
834+ Spec : templatev1.TemplateInstanceSpec {
835+ Template : templatev1.Template {
836+ ObjectMeta : metav1.ObjectMeta {
837+ Name : "test-template" ,
838+ },
839+ },
840+ Secret : & corev1.LocalObjectReference {
841+ Name : "test-secret" ,
842+ },
843+ },
844+ Status : templatev1.TemplateInstanceStatus {
845+ Conditions : []templatev1.TemplateInstanceCondition {},
846+ Objects : []templatev1.TemplateInstanceObject {},
847+ },
848+ },
849+ want : []string {
850+ "Parameters" ,
851+ },
852+ },
853+ }
854+
855+ for _ , tt := range tests {
856+ t .Run (tt .name , func (t * testing.T ) {
857+ kubeClient := fake .NewSimpleClientset ()
858+ describer := & TemplateInstanceDescriber {
859+ kubeClient : kubeClient ,
860+ }
861+
862+ result , err := describer .DescribeTemplateInstance (tt .templateInstance , "test-namespace" , describe.DescriberSettings {})
863+ if err != nil {
864+ t .Fatalf ("DescribeTemplateInstance failed: %v" , err )
865+ }
866+
867+ for _ , expected := range tt .want {
868+ if ! strings .Contains (result , expected ) {
869+ t .Errorf ("Expected output to contain %q, but got:\n %s" , expected , result )
870+ }
871+ }
872+ })
873+ }
874+ }
0 commit comments