...
1
16
17 package discovery
18
19 import (
20 "testing"
21 "time"
22
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
25 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
26 )
27
28 func TestFor(t *testing.T) {
29 tests := []struct {
30 name string
31 d kubeadm.JoinConfiguration
32 expect bool
33 }{
34 {
35 name: "default Discovery",
36 d: kubeadm.JoinConfiguration{},
37 expect: false,
38 },
39 {
40 name: "file Discovery with a path",
41 d: kubeadm.JoinConfiguration{
42 Discovery: kubeadm.Discovery{
43 File: &kubeadm.FileDiscovery{
44 KubeConfigPath: "notnil",
45 },
46 },
47 },
48 expect: false,
49 },
50 {
51 name: "file Discovery with an url",
52 d: kubeadm.JoinConfiguration{
53 Discovery: kubeadm.Discovery{
54 File: &kubeadm.FileDiscovery{
55 KubeConfigPath: "https://localhost",
56 },
57 },
58 },
59 expect: false,
60 },
61 {
62 name: "BootstrapTokenDiscovery",
63 d: kubeadm.JoinConfiguration{
64 Discovery: kubeadm.Discovery{
65 BootstrapToken: &kubeadm.BootstrapTokenDiscovery{
66 Token: "foo.bar@foobar",
67 },
68 },
69 },
70 expect: false,
71 },
72 }
73 for _, rt := range tests {
74 t.Run(rt.name, func(t *testing.T) {
75 config := rt.d
76 config.Timeouts = &kubeadm.Timeouts{
77 Discovery: &metav1.Duration{Duration: 1 * time.Minute},
78 }
79 _, actual := For(&config)
80 if (actual == nil) != rt.expect {
81 t.Errorf(
82 "failed For:\n\texpected: %t\n\t actual: %t",
83 rt.expect,
84 (actual == nil),
85 )
86 }
87 })
88 }
89 }
90
View as plain text