Skip to content

Commit d01dc84

Browse files
committed
container-test: fix not running unit tests in cmd
So, build/unit-in-container.sh never ran any tests under cmd. This happened because the $(go list ...) in BUILD_CMD was not escaped, and therefore the expansion happened before cd. Here is a demo: [kir@kir-rhat cadvisor]$ BUILD_CMD="pwd && cd cmd && echo $(pwd)" [kir@kir-rhat cadvisor]$ echo $BUILD_CMD pwd && cd cmd && echo /home/kir/go/src/github.com/google/cadvisor The fix would be to escape the $ in $(go list): [kir@kir-rhat cadvisor]$ BUILD_CMD="pwd && cd cmd && echo \$(pwd)" [kir@kir-rhat cadvisor]$ echo $BUILD_CMD pwd && cd cmd && echo $(pwd) [kir@kir-rhat cadvisor]$ sh -c "$BUILD_CMD" /home/kir/go/src/github.com/google/cadvisor /home/kir/go/src/github.com/google/cadvisor/cmd Yet, it's easier just to reuse the make test target which already has the exclusion logic. For that to work properly with custom test configs from ./build/config, we need to export GO_FLAGS env var into container. While at it, slightly simplify the BUILD_CMD by adding -e to bash, so we do not have to specify && every time. Fixes: 74b513b Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 0600934 commit d01dc84

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

build/unit-in-container.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -e
17+
set -ex
1818

1919
if ! CONTAINER_ENGINE=$(command -v docker || command -v podman); then
2020
echo "Neither docker nor podman found. Exiting."
2121
exit 1
2222
fi
2323

2424
function run_tests() {
25-
BUILD_CMD="go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ') && \
26-
cd cmd && go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ')"
25+
BUILD_CMD="make test"
2726
if [ "$BUILD_PACKAGES" != "" ]; then
28-
BUILD_CMD="echo 'deb http://deb.debian.org/debian buster-backports main'>/etc/apt/sources.list.d/buster.list && \
29-
apt update && \
30-
apt install -y -t buster-backports $BUILD_PACKAGES && \
27+
BUILD_CMD="echo 'deb http://deb.debian.org/debian buster-backports main'>/etc/apt/sources.list.d/buster.list
28+
apt update
29+
apt install -y -t buster-backports $BUILD_PACKAGES
3130
$BUILD_CMD"
3231
fi
3332

3433
$CONTAINER_ENGINE run --rm \
3534
-w /go/src/github.com/google/cadvisor \
3635
-v ${PWD}:/go/src/github.com/google/cadvisor \
36+
-e GO_FLAGS \
3737
golang:${GOLANG_VERSION} \
38-
bash -c "$BUILD_CMD"
38+
bash -e -c "$BUILD_CMD"
3939
}
4040

4141
GO_FLAGS=${GO_FLAGS:-"-tags=netgo -race"}

0 commit comments

Comments
 (0)