Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
cf6b6778
Commit
cf6b6778
authored
Oct 27, 2016
by
Jacob Beacham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding CLI tests for kubeadm.
parent
5e66509a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
172 additions
and
1 deletion
+172
-1
Makefile
Makefile
+1
-0
BUILD
cmd/kubeadm/app/cmd/BUILD
+5
-1
BUILD
cmd/kubeadm/test/BUILD
+25
-0
token_test.go
cmd/kubeadm/test/token_test.go
+65
-0
util.go
cmd/kubeadm/test/util.go
+41
-0
test-kubeadm-cmd.sh
hack/make-rules/test-kubeadm-cmd.sh
+32
-0
test.sh
hack/make-rules/test.sh
+1
-0
known-flags.txt
hack/verify-flags/known-flags.txt
+1
-0
test_owners.csv
test/test_owners.csv
+1
-0
No files found.
Makefile
View file @
cf6b6778
...
@@ -185,6 +185,7 @@ test-e2e-node: ginkgo generated_files
...
@@ -185,6 +185,7 @@ test-e2e-node: ginkgo generated_files
# make test-cmd
# make test-cmd
.PHONY
:
test-cmd
.PHONY
:
test-cmd
test-cmd
:
generated_files
test-cmd
:
generated_files
hack/make-rules/test-kubeadm-cmd.sh
hack/make-rules/test-cmd.sh
hack/make-rules/test-cmd.sh
# Remove all build artifacts.
# Remove all build artifacts.
...
...
cmd/kubeadm/app/cmd/BUILD
View file @
cf6b6778
...
@@ -17,6 +17,7 @@ go_library(
...
@@ -17,6 +17,7 @@ go_library(
"init.go",
"init.go",
"join.go",
"join.go",
"reset.go",
"reset.go",
"token.go",
"version.go",
"version.go",
],
],
tags = ["automanaged"],
tags = ["automanaged"],
...
@@ -42,7 +43,10 @@ go_library(
...
@@ -42,7 +43,10 @@ go_library(
go_test(
go_test(
name = "go_default_test",
name = "go_default_test",
srcs = ["reset_test.go"],
srcs = [
"reset_test.go",
"token_test.go",
],
library = "go_default_library",
library = "go_default_library",
tags = ["automanaged"],
tags = ["automanaged"],
deps = ["//cmd/kubeadm/app/preflight:go_default_library"],
deps = ["//cmd/kubeadm/app/preflight:go_default_library"],
...
...
cmd/kubeadm/test/BUILD
0 → 100644
View file @
cf6b6778
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
"go_test",
"cgo_library",
)
go_library(
name = "go_default_library",
srcs = ["util.go"],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = ["token_test.go"],
library = "go_default_library",
tags = ["automanaged"],
deps = [],
)
cmd/kubeadm/test/token_test.go
0 → 100644
View file @
cf6b6778
/*
Copyright 2016 The Kubernetes 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
kubeadm
import
(
"flag"
"regexp"
"testing"
)
const
(
TokenExpectedRegex
=
"^
\\
S{6}
\\
.
\\
S{16}
\n
$"
)
var
kubeadmPath
string
func
init
()
{
flag
.
StringVar
(
&
kubeadmPath
,
"kubeadm-path"
,
"cluster/kubeadm.sh"
,
"Location of kubeadm"
)
}
func
TestCmdTokenGenerate
(
t
*
testing
.
T
)
{
stdout
,
_
,
err
:=
RunCmd
(
kubeadmPath
,
"token"
,
"generate"
)
if
err
!=
nil
{
t
.
Errorf
(
"'kubeadm token generate' exited uncleanly: %v"
,
err
)
}
matched
,
err
:=
regexp
.
MatchString
(
TokenExpectedRegex
,
stdout
)
if
err
!=
nil
{
t
.
Fatalf
(
"encountered an error while trying to match 'kubeadm token generate' stdout: %v"
,
err
)
}
if
!
matched
{
t
.
Errorf
(
"'kubeadm token generate' stdout did not match expected regex; wanted: [%s], got: [%s]"
,
TokenExpectedRegex
,
stdout
)
}
}
func
TestCmdTokenGenerateTypoError
(
t
*
testing
.
T
)
{
/*
Since we expect users to do things like this:
$ TOKEN=$(kubeadm token generate)
we want to make sure that if they have a typo in their command, we exit
with a non-zero status code after showing the command's usage, so that
the usage itself isn't captured as a token without the user noticing.
*/
_
,
_
,
err
:=
RunCmd
(
kubeadmPath
,
"token"
,
"genorate"
)
// subtle typo
if
err
==
nil
{
t
.
Error
(
"'kubeadm token genorate' (a deliberate typo) exited without an error when we expected non-zero exit status"
)
}
}
cmd/kubeadm/test/util.go
0 → 100644
View file @
cf6b6778
/*
Copyright 2016 The Kubernetes 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
kubeadm
import
(
"bytes"
"fmt"
"io"
"os"
"os/exec"
)
// Forked from test/e2e/framework because the e2e framework is quite bloated
// for our purposes here, and modified to remove undesired logging.
func
RunCmd
(
command
string
,
args
...
string
)
(
string
,
string
,
error
)
{
var
bout
,
berr
bytes
.
Buffer
cmd
:=
exec
.
Command
(
command
,
args
...
)
cmd
.
Stdout
=
io
.
MultiWriter
(
os
.
Stdout
,
&
bout
)
cmd
.
Stderr
=
io
.
MultiWriter
(
os
.
Stderr
,
&
berr
)
err
:=
cmd
.
Run
()
stdout
,
stderr
:=
bout
.
String
(),
berr
.
String
()
if
err
!=
nil
{
return
""
,
""
,
fmt
.
Errorf
(
"error running %s %v; got error %v, stdout %q, stderr %q"
,
command
,
args
,
err
,
stdout
,
stderr
)
}
return
stdout
,
stderr
,
nil
}
hack/make-rules/test-kubeadm-cmd.sh
0 → 100755
View file @
cf6b6778
#!/bin/bash
# Copyright 2016 The Kubernetes 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.
set
-o
errexit
set
-o
nounset
set
-o
pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/../..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
KUBEADM_PATH
=
"
${
KUBEADM_PATH
:
=
$(
kube::realpath
"
${
KUBE_ROOT
}
"
)
/cluster/kubeadm.sh
}
"
# If testing a different version of kubeadm than the current build, you can
# comment this out to save yourself from needlessly building here.
make
-C
"
${
KUBE_ROOT
}
"
WHAT
=
cmd/kubeadm
make
-C
"
${
KUBE_ROOT
}
"
test
\
WHAT
=
cmd/kubeadm/test
\
KUBE_TEST_ARGS
=
"--kubeadm-path '
${
KUBEADM_PATH
}
'"
hack/make-rules/test.sh
View file @
cf6b6778
...
@@ -35,6 +35,7 @@ kube::test::find_dirs() {
...
@@ -35,6 +35,7 @@ kube::test::find_dirs() {
-path
'./_artifacts/*'
\
-path
'./_artifacts/*'
\
-o
-path
'./_output/*'
\
-o
-path
'./_output/*'
\
-o
-path
'./_gopath/*'
\
-o
-path
'./_gopath/*'
\
-o
-path
'./cmd/kubeadm/test/*'
\
-o
-path
'./contrib/podex/*'
\
-o
-path
'./contrib/podex/*'
\
-o
-path
'./output/*'
\
-o
-path
'./output/*'
\
-o
-path
'./release/*'
\
-o
-path
'./release/*'
\
...
...
hack/verify-flags/known-flags.txt
View file @
cf6b6778
...
@@ -295,6 +295,7 @@ kube-master
...
@@ -295,6 +295,7 @@ kube-master
kube-master
kube-master
kube-master-url
kube-master-url
kube-reserved
kube-reserved
kubeadm-path
kubecfg-file
kubecfg-file
kubectl-path
kubectl-path
kubelet-address
kubelet-address
...
...
test/test_owners.csv
View file @
cf6b6778
...
@@ -457,6 +457,7 @@ k8s.io/kubernetes/cmd/kubeadm/app/cmd,caesarxuchao,1
...
@@ -457,6 +457,7 @@ k8s.io/kubernetes/cmd/kubeadm/app/cmd,caesarxuchao,1
k8s.io/kubernetes/cmd/kubeadm/app/images,davidopp,1
k8s.io/kubernetes/cmd/kubeadm/app/images,davidopp,1
k8s.io/kubernetes/cmd/kubeadm/app/preflight,apprenda,0
k8s.io/kubernetes/cmd/kubeadm/app/preflight,apprenda,0
k8s.io/kubernetes/cmd/kubeadm/app/util,krousey,1
k8s.io/kubernetes/cmd/kubeadm/app/util,krousey,1
k8s.io/kubernetes/cmd/kubeadm/test,pipejakob,0
k8s.io/kubernetes/cmd/kubelet/app,hurf,1
k8s.io/kubernetes/cmd/kubelet/app,hurf,1
k8s.io/kubernetes/cmd/libs/go2idl/client-gen/types,caesarxuchao,0
k8s.io/kubernetes/cmd/libs/go2idl/client-gen/types,caesarxuchao,0
k8s.io/kubernetes/cmd/libs/go2idl/go-to-protobuf/protobuf,smarterclayton,0
k8s.io/kubernetes/cmd/libs/go2idl/go-to-protobuf/protobuf,smarterclayton,0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment