mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #41367 from apprenda/kubeadm_validation_pkg_tests
Automatic merge from submit-queue (batch tested with PRs 41342, 41257, 41295, 41367, 41230) kubeadm: unit tests for apis/kubeadm/validation **What this PR does / why we need it**: added tests to apis/kubeadm/validation pkg and raised coverage from ~21% to 100%. Adding unit tests is a WIP from #34136 **Special notes for your reviewer**: /cc @luxas @pires **Release note**: ```release-note NONE ```
This commit is contained in:
commit
416c1a498e
@ -38,5 +38,8 @@ go_test(
|
|||||||
srcs = ["validation_test.go"],
|
srcs = ["validation_test.go"],
|
||||||
library = ":go_default_library",
|
library = ":go_default_library",
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = ["//vendor:k8s.io/apimachinery/pkg/util/validation/field"],
|
deps = [
|
||||||
|
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/util/validation/field",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateServiceSubnet(t *testing.T) {
|
func TestValidateServiceSubnet(t *testing.T) {
|
||||||
@ -46,3 +47,101 @@ func TestValidateServiceSubnet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateMasterConfiguration(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
s *kubeadm.MasterConfiguration
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{&kubeadm.MasterConfiguration{}, false},
|
||||||
|
{&kubeadm.MasterConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
HTTPS: &kubeadm.HTTPSDiscovery{URL: "foo"},
|
||||||
|
File: &kubeadm.FileDiscovery{Path: "foo"},
|
||||||
|
Token: &kubeadm.TokenDiscovery{
|
||||||
|
ID: "abcdef",
|
||||||
|
Secret: "1234567890123456",
|
||||||
|
Addresses: []string{"foobar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, false},
|
||||||
|
{&kubeadm.MasterConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
HTTPS: &kubeadm.HTTPSDiscovery{URL: "foo"},
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
{&kubeadm.MasterConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
File: &kubeadm.FileDiscovery{Path: "foo"},
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
{&kubeadm.MasterConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
Token: &kubeadm.TokenDiscovery{
|
||||||
|
ID: "abcdef",
|
||||||
|
Secret: "1234567890123456",
|
||||||
|
Addresses: []string{"foobar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
}
|
||||||
|
for _, rt := range tests {
|
||||||
|
actual := ValidateMasterConfiguration(rt.s)
|
||||||
|
if (len(actual) == 0) != rt.expected {
|
||||||
|
t.Errorf(
|
||||||
|
"failed ValidateMasterConfiguration:\n\texpected: %t\n\t actual: %t",
|
||||||
|
rt.expected,
|
||||||
|
(len(actual) == 0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateNodeConfiguration(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
s *kubeadm.NodeConfiguration
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{&kubeadm.NodeConfiguration{}, false},
|
||||||
|
{&kubeadm.NodeConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
HTTPS: &kubeadm.HTTPSDiscovery{URL: "foo"},
|
||||||
|
File: &kubeadm.FileDiscovery{Path: "foo"},
|
||||||
|
Token: &kubeadm.TokenDiscovery{
|
||||||
|
ID: "abcdef",
|
||||||
|
Secret: "1234567890123456",
|
||||||
|
Addresses: []string{"foobar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, false},
|
||||||
|
{&kubeadm.NodeConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
HTTPS: &kubeadm.HTTPSDiscovery{URL: "foo"},
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
{&kubeadm.NodeConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
File: &kubeadm.FileDiscovery{Path: "foo"},
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
{&kubeadm.NodeConfiguration{
|
||||||
|
Discovery: kubeadm.Discovery{
|
||||||
|
Token: &kubeadm.TokenDiscovery{
|
||||||
|
ID: "abcdef",
|
||||||
|
Secret: "1234567890123456",
|
||||||
|
Addresses: []string{"foobar"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, true},
|
||||||
|
}
|
||||||
|
for _, rt := range tests {
|
||||||
|
actual := ValidateNodeConfiguration(rt.s)
|
||||||
|
if (len(actual) == 0) != rt.expected {
|
||||||
|
t.Errorf(
|
||||||
|
"failed ValidateNodeConfiguration:\n\texpected: %t\n\t actual: %t",
|
||||||
|
rt.expected,
|
||||||
|
(len(actual) == 0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user