mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #128214 from googs1025/chore/printers/ut
chore(printers): add unit test coverage for printers part
This commit is contained in:
commit
b95484e330
@ -6775,6 +6775,125 @@ func TestPrintScale(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrintClusterTrustBundle(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
bundle certificates.ClusterTrustBundle
|
||||||
|
options printers.GenerateOptions
|
||||||
|
expected []metav1.TableRow
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
bundle: certificates.ClusterTrustBundle{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-cluster-trust-bundle",
|
||||||
|
},
|
||||||
|
Spec: certificates.ClusterTrustBundleSpec{
|
||||||
|
SignerName: "test-signer-name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []metav1.TableRow{
|
||||||
|
{
|
||||||
|
Cells: []interface{}{"test-cluster-trust-bundle", "test-signer-name"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
rows, err := printClusterTrustBundle(&test.bundle, test.options)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := range rows {
|
||||||
|
rows[i].Object.Object = nil
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(test.expected, rows) {
|
||||||
|
t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrintValidatingAdmissionPolicyBinding(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
validatingAdmissionPolicyBinding admissionregistration.ValidatingAdmissionPolicyBinding
|
||||||
|
options printers.GenerateOptions
|
||||||
|
expected []metav1.TableRow
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
validatingAdmissionPolicyBinding: admissionregistration.ValidatingAdmissionPolicyBinding{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "config",
|
||||||
|
CreationTimestamp: metav1.Time{Time: time.Now().Add(-3e11)},
|
||||||
|
},
|
||||||
|
Spec: admissionregistration.ValidatingAdmissionPolicyBindingSpec{
|
||||||
|
PolicyName: "test-scale.example.com",
|
||||||
|
ParamRef: &admissionregistration.ParamRef{
|
||||||
|
Name: "test-scale-setting.example.com",
|
||||||
|
ParameterNotFoundAction: ptr.To(admissionregistration.DenyAction),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []metav1.TableRow{
|
||||||
|
{
|
||||||
|
Cells: []interface{}{"config", "test-scale.example.com", "*/test-scale-setting.example.com", "5m"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
rows, err := printValidatingAdmissionPolicyBinding(&test.validatingAdmissionPolicyBinding, test.options)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := range rows {
|
||||||
|
rows[i].Object.Object = nil
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(test.expected, rows) {
|
||||||
|
t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrintLeaseCandidate(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
leaseCandidate coordination.LeaseCandidate
|
||||||
|
options printers.GenerateOptions
|
||||||
|
expected []metav1.TableRow
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
leaseCandidate: coordination.LeaseCandidate{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test-lease",
|
||||||
|
CreationTimestamp: metav1.Time{Time: time.Now().Add(-3e11)},
|
||||||
|
},
|
||||||
|
Spec: coordination.LeaseCandidateSpec{
|
||||||
|
BinaryVersion: "test-binary-version",
|
||||||
|
EmulationVersion: "test-emulation-version",
|
||||||
|
LeaseName: "test-lease-name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []metav1.TableRow{
|
||||||
|
{
|
||||||
|
Cells: []interface{}{"test-lease", "test-lease-name", "test-binary-version", "test-emulation-version", "5m"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
rows, err := printLeaseCandidate(&test.leaseCandidate, test.options)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := range rows {
|
||||||
|
rows[i].Object.Object = nil
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(test.expected, rows) {
|
||||||
|
t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTableRowDeepCopyShouldNotPanic(t *testing.T) {
|
func TestTableRowDeepCopyShouldNotPanic(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -7092,6 +7211,18 @@ func TestTableRowDeepCopyShouldNotPanic(t *testing.T) {
|
|||||||
return printResourceSlice(&resourceapis.ResourceSlice{}, printers.GenerateOptions{})
|
return printResourceSlice(&resourceapis.ResourceSlice{}, printers.GenerateOptions{})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "LeaseCandidate",
|
||||||
|
printer: func() ([]metav1.TableRow, error) {
|
||||||
|
return printLeaseCandidate(&coordination.LeaseCandidate{}, printers.GenerateOptions{})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ClusterTrustBundle",
|
||||||
|
printer: func() ([]metav1.TableRow, error) {
|
||||||
|
return printClusterTrustBundle(&certificates.ClusterTrustBundle{}, printers.GenerateOptions{})
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user