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
901a5dbe
Commit
901a5dbe
authored
Mar 25, 2015
by
Jeff Grafton
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5687 from nikhiljindal/client_test
Updating test-go.sh and test-integration.sh to be able to run the tests for multiple API versions
parents
6145b3b9
5e4ab8e0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
87 deletions
+119
-87
.travis.yml
.travis.yml
+8
-5
test-go.sh
hack/test-go.sh
+102
-80
test-integration.sh
hack/test-integration.sh
+9
-2
No files found.
.travis.yml
View file @
901a5dbe
...
...
@@ -2,9 +2,12 @@ sudo: false
language
:
go
go
:
-
1.4
-
1.3
matrix
:
include
:
-
go
:
1.4
env
:
KUBE_TEST_API_VERSIONS="v1beta1"
-
go
:
1.3
env
:
KUBE_TEST_API_VERSIONS="v1beta3"
install
:
-
if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
...
...
@@ -18,10 +21,10 @@ install:
-
GOPATH=$PWD/Godeps/_workspace:$GOPATH go install ./...
script
:
-
KUBE_RACE="-race" KUBE_COVER="y" KUBE_GOVERALLS_BIN="$HOME/gopath/bin/goveralls" KUBE_TIMEOUT='-timeout 300s' KUBE_COVERPROCS=8 ./hack/test-go.sh -- -p=2
-
KUBE_RACE="-race" KUBE_COVER="y" KUBE_GOVERALLS_BIN="$HOME/gopath/bin/goveralls" KUBE_TIMEOUT='-timeout 300s' KUBE_COVERPROCS=8
KUBE_TEST_API_VERSIONS=$KUBE_TEST_API_VERSIONS
./hack/test-go.sh -- -p=2
-
PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-cmd.sh
-
PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/verify-gendocs.sh
-
PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-integration.sh
-
PATH=$HOME/gopath/bin:./third_party/etcd:$PATH
KUBE_TEST_API_VERSIONS=$KUBE_TEST_API_VERSIONS
./hack/test-integration.sh
notifications
:
irc
:
"
chat.freenode.net#google-containers"
hack/test-go.sh
View file @
901a5dbe
...
...
@@ -50,6 +50,8 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4}
KUBE_RACE
=
${
KUBE_RACE
:-}
# use KUBE_RACE="-race" to enable race testing
# Set to the goveralls binary path to report coverage results to Coveralls.io.
KUBE_GOVERALLS_BIN
=
${
KUBE_GOVERALLS_BIN
:-}
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS
=
${
KUBE_TEST_API_VERSIONS
:-
"v1beta1,v1beta3"
}
kube::test::usage
()
{
kube::log::usage_from_stdin
<<
EOF
...
...
@@ -109,87 +111,107 @@ if [[ ${#testcases[@]} -eq 0 ]]; then
fi
set
--
"
${
testcases
[@]+
${
testcases
[@]
}}
"
# TODO: this should probably be refactored to avoid code duplication with the
# coverage version.
if
[[
$iterations
-gt
1
]]
;
then
if
[[
$#
-eq
0
]]
;
then
set
--
$(
kube::test::find_dirs
)
runTests
()
{
# TODO: this should probably be refactored to avoid code duplication with the
# coverage version.
if
[[
$iterations
-gt
1
]]
;
then
if
[[
$#
-eq
0
]]
;
then
set
--
$(
kube::test::find_dirs
)
fi
kube::log::status
"Running
${
iterations
}
times"
fails
=
0
for
arg
;
do
trap
'exit 1'
SIGINT
pkg
=
${
KUBE_GO_PACKAGE
}
/
${
arg
}
kube::log::status
"
${
pkg
}
"
# keep going, even if there are failures
pass
=
0
count
=
0
for
i
in
$(
seq
1
${
iterations
})
;
do
if
go
test
"
${
goflags
[@]
:+
${
goflags
[@]
}}
"
\
${
KUBE_RACE
}
${
KUBE_TIMEOUT
}
"
${
pkg
}
"
;
then
pass
=
$((
pass
+
1
))
else
fails
=
$((
fails
+
1
))
fi
count
=
$((
count
+
1
))
done
2>&1
kube::log::status
"
${
pass
}
/
${
count
}
passed"
done
if
[[
${
fails
}
-gt
0
]]
;
then
return
1
else
return
0
fi
fi
kube::log::status
"Running
${
iterations
}
times"
fails
=
0
for
arg
;
do
trap
'exit 1'
SIGINT
pkg
=
${
KUBE_GO_PACKAGE
}
/
${
arg
}
kube::log::status
"
${
pkg
}
"
# keep going, even if there are failures
pass
=
0
count
=
0
for
i
in
$(
seq
1
${
iterations
})
;
do
if
go
test
"
${
goflags
[@]
:+
${
goflags
[@]
}}
"
\
${
KUBE_RACE
}
${
KUBE_TIMEOUT
}
"
${
pkg
}
"
;
then
pass
=
$((
pass
+
1
))
else
fails
=
$((
fails
+
1
))
fi
count
=
$((
count
+
1
))
done
2>&1
kube::log::status
"
${
pass
}
/
${
count
}
passed"
done
if
[[
${
fails
}
-gt
0
]]
;
then
exit
1
else
exit
0
# If we're not collecting coverage, run all requested tests with one 'go test'
# command, which is much faster.
if
[[
!
${
KUBE_COVER
}
=
~ ^[yY]
$
]]
;
then
kube::log::status
"Running unit tests without code coverage"
go
test
"
${
goflags
[@]
:+
${
goflags
[@]
}}
"
\
${
KUBE_RACE
}
${
KUBE_TIMEOUT
}
"
${
@+
${
@/#/
${
KUBE_GO_PACKAGE
}
/
}}
"
return
0
fi
fi
# If we're not collecting coverage, run all requested tests with one 'go test'
# command, which is much faster.
if
[[
!
${
KUBE_COVER
}
=
~ ^[yY]
$
]]
;
then
kube::log::status
"Running unit tests without code coverage"
go
test
"
${
goflags
[@]
:+
${
goflags
[@]
}}
"
\
${
KUBE_RACE
}
${
KUBE_TIMEOUT
}
"
${
@+
${
@/#/
${
KUBE_GO_PACKAGE
}
/
}}
"
exit
0
fi
# Create coverage report directories.
cover_report_dir
=
"/tmp/k8s_coverage/
${
KUBE_API_VERSION
}
/
$(
kube::util::sortable_date
)
"
cover_profile
=
"coverage.out"
# Name for each individual coverage profile
kube::log::status
"Saving coverage output in '
${
cover_report_dir
}
'"
mkdir
-p
"
${
@+
${
@/#/
${
cover_report_dir
}
/
}}
"
# Run all specified tests, collecting coverage results. Go currently doesn't
# support collecting coverage across multiple packages at once, so we must issue
# separate 'go test' commands for each package and then combine at the end.
# To speed things up considerably, we can at least use xargs -P to run multiple
# 'go test' commands at once.
printf
"%s
\n
"
"
${
@
}
"
| xargs
-I
{}
-n1
-P
${
KUBE_COVERPROCS
}
\
go
test
"
${
goflags
[@]
:+
${
goflags
[@]
}}
"
\
${
KUBE_RACE
}
\
${
KUBE_TIMEOUT
}
\
-cover
-covermode
=
"
${
KUBE_COVERMODE
}
"
\
-coverprofile
=
"
${
cover_report_dir
}
/{}/
${
cover_profile
}
"
\
"
${
cover_params
[@]+
${
cover_params
[@]
}}
"
\
"
${
KUBE_GO_PACKAGE
}
/{}"
COMBINED_COVER_PROFILE
=
"
${
cover_report_dir
}
/combined-coverage.out"
{
# The combined coverage profile needs to start with a line indicating which
# coverage mode was used (set, count, or atomic). This line is included in
# each of the coverage profiles generated when running 'go test -cover', but
# we strip these lines out when combining so that there's only one.
echo
"mode:
${
KUBE_COVERMODE
}
"
# Include all coverage reach data in the combined profile, but exclude the
# 'mode' lines, as there should be only one.
for
x
in
`
find
"
${
cover_report_dir
}
"
-name
"
${
cover_profile
}
"
`
;
do
cat
$x
|
grep
-h
-v
"^mode:"
||
true
done
}
>
"
${
COMBINED_COVER_PROFILE
}
"
coverage_html_file
=
"
${
cover_report_dir
}
/combined-coverage.html"
go tool cover
-html
=
"
${
COMBINED_COVER_PROFILE
}
"
-o
=
"
${
coverage_html_file
}
"
kube::log::status
"Combined coverage report:
${
coverage_html_file
}
"
}
# Create coverage report directories.
cover_report_dir
=
"/tmp/k8s_coverage/
$(
kube::util::sortable_date
)
"
cover_profile
=
"coverage.out"
# Name for each individual coverage profile
kube::log::status
"Saving coverage output in '
${
cover_report_dir
}
'"
mkdir
-p
"
${
@+
${
@/#/
${
cover_report_dir
}
/
}}
"
# Run all specified tests, collecting coverage results. Go currently doesn't
# support collecting coverage across multiple packages at once, so we must issue
# separate 'go test' commands for each package and then combine at the end.
# To speed things up considerably, we can at least use xargs -P to run multiple
# 'go test' commands at once.
printf
"%s
\n
"
"
${
@
}
"
| xargs
-I
{}
-n1
-P
${
KUBE_COVERPROCS
}
\
go
test
"
${
goflags
[@]
:+
${
goflags
[@]
}}
"
\
${
KUBE_RACE
}
\
${
KUBE_TIMEOUT
}
\
-cover
-covermode
=
"
${
KUBE_COVERMODE
}
"
\
-coverprofile
=
"
${
cover_report_dir
}
/{}/
${
cover_profile
}
"
\
"
${
cover_params
[@]+
${
cover_params
[@]
}}
"
\
"
${
KUBE_GO_PACKAGE
}
/{}"
combined_cover_profile
=
"
${
cover_report_dir
}
/combined-coverage.out"
{
# The combined coverage profile needs to start with a line indicating which
# coverage mode was used (set, count, or atomic). This line is included in
# each of the coverage profiles generated when running 'go test -cover', but
# we strip these lines out when combining so that there's only one.
echo
"mode:
${
KUBE_COVERMODE
}
"
# Include all coverage reach data in the combined profile, but exclude the
# 'mode' lines, as there should be only one.
for
x
in
`
find
"
${
cover_report_dir
}
"
-name
"
${
cover_profile
}
"
`
;
do
cat
$x
|
grep
-h
-v
"^mode:"
||
true
done
}
>
"
${
combined_cover_profile
}
"
coverage_html_file
=
"
${
cover_report_dir
}
/combined-coverage.html"
go tool cover
-html
=
"
${
combined_cover_profile
}
"
-o
=
"
${
coverage_html_file
}
"
kube::log::status
"Combined coverage report:
${
coverage_html_file
}
"
if
[[
-x
"
${
KUBE_GOVERALLS_BIN
}
"
]]
;
then
${
KUBE_GOVERALLS_BIN
}
-coverprofile
=
"
${
combined_cover_profile
}
"
||
true
fi
runTestsForVersion
()
{
export
KUBE_API_VERSION
=
"
$1
"
runTests
"
${
@
:2
}
"
}
reportCoverageToCoveralls
()
{
if
[[
-x
"
${
KUBE_GOVERALLS_BIN
}
"
]]
;
then
${
KUBE_GOVERALLS_BIN
}
-coverprofile
=
"
${
COMBINED_COVER_PROFILE
}
"
||
true
fi
}
# Convert the CSV to an array of API versions to test
IFS
=
','
read
-a
apiVersions
<<<
${
KUBE_TEST_API_VERSIONS
}
for
apiVersion
in
"
${
apiVersions
[@]
}
"
;
do
echo
"Running tests for APIVersion:
$apiVersion
"
runTestsForVersion
$apiVersion
"
${
@
}
"
done
# We might run the tests for multiple versions, but we want to report only
# one of them to coveralls. Here we report coverage from the last run.
reportCoverageToCoveralls
hack/test-integration.sh
View file @
901a5dbe
...
...
@@ -24,6 +24,9 @@ set -o pipefail
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS
=
${
KUBE_TEST_API_VERSIONS
:-
"v1beta1,v1beta3"
}
cleanup
()
{
kube::etcd::cleanup
...
...
@@ -36,6 +39,7 @@ runTests() {
kube::log::status
"Running integration test cases"
KUBE_GOFLAGS
=
"-tags 'integration no-docker' "
\
KUBE_RACE
=
"-race"
\
KUBE_TEST_API_VERSIONS
=
"
$1
"
\
"
${
KUBE_ROOT
}
/hack/test-go.sh"
test
/integration
kube::log::status
"Running integration test scenario"
...
...
@@ -50,5 +54,8 @@ runTests() {
# Run cleanup to stop etcd on interrupt or other kill signal.
trap
cleanup EXIT
runTests
"v1beta1"
runTests
"v1beta3"
# Convert the CSV to an array of API versions to test
IFS
=
','
read
-a
apiVersions
<<<
${
KUBE_TEST_API_VERSIONS
}
for
apiVersion
in
"
${
apiVersions
[@]
}
"
;
do
runTests
$apiVersion
done
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