Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some initial shell parsing tests. #51649

Merged
merged 2 commits into from Sep 1, 2017
Merged

Conversation

mml
Copy link
Contributor

@mml mml commented Aug 30, 2017

These just test to see if there is a bash syntax error in these shell
libraries.

For #51642

NONE

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 30, 2017
@k8s-github-robot k8s-github-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Aug 30, 2017
@mml
Copy link
Contributor Author

mml commented Aug 30, 2017

I have absolutely no idea if this is a good approach or not, so please feel free to suggest alternate/better ways to achieve this.

/assign @ixdy

@mml mml unassigned eparis Aug 30, 2017
@mml mml changed the title Add some initial parsing shell tests. Add some initial shell parsing tests. Aug 30, 2017
@cblecker
Copy link
Member

you probably want something like this to ensure fail on non-zero exit:

set -o errexit
set -o nounset
set -o pipefail

@mml mml force-pushed the sh-test branch 3 times, most recently from 4e4c2d7 to ef03933 Compare August 30, 2017 21:17
Copy link
Member

@ixdy ixdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically LG, with a few minor nits/comments.

set -o pipefail

# Setup test environment
source hack/test-shlib.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to base these off ${KUBE_ROOT} so that you can call this script from somewhere besides ${KUBE_ROOT}?

cluster/BUILD Outdated
@@ -46,3 +46,33 @@ pkg_tar(
"//cluster/saltbase:salt-manifests",
],
)

sh_test(
name = "common",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may want to suffix all of these with _test. otherwise you have a weird target named //cluster:common which is actually a test, for example.

set -o pipefail

# HOME is, by default, not set. Give it a bogus value.
HOME=${PWD}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a tmp dir instead?

hack/BUILD Outdated
@@ -14,6 +14,11 @@ filegroup(
visibility = ["//visibility:private"],
)

sh_library(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add testonly = True?

cluster/BUILD Outdated
name = "common",
srcs = ["common_test.sh"],
data = [
"all-srcs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

":all-srcs" (add the leading :) is preferred for referencing rules in the same package.

@ixdy
Copy link
Member

ixdy commented Aug 30, 2017

an alternative to having hack/test-shlib.sh which sets $HOME to something is to set $HOME in the bazel args with --test_env, something like

--- a/build/root/.bazelrc
+++ b/build/root/.bazelrc
@@ -11,3 +11,6 @@ build --sandbox_tmpfs_path=/tmp
 # Ensure that Bazel never runs as root, which can cause unit tests to fail.
 # This flag requires Bazel 0.5.0+
 build --sandbox_fake_username
+
+# Set HOME in the test environment to something bogus
+test --test_env HOME=/tmp/bazel-fake-home

Another alternative is having cluster/common.sh not blow up if $HOME is unset.

I'm not sure whether either of these is better than what you're already doing.

@mml
Copy link
Contributor Author

mml commented Aug 30, 2017

I don't like the bazel flag option, because it requires that flag or the test signals a failure. It also seems a little too broad for me to make it (because it changes the environment on all tests), so I'd rather not.

The other idea, fixing cluster/common.sh, is easy enough. I'll just use ${HOME:-.}

@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 30, 2017
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 30, 2017
@mml
Copy link
Contributor Author

mml commented Aug 30, 2017

@ixdy I think I got all the style fixes and sidestepped most of the other issues by just executing the files directly as tests.

PTAL

cluster/BUILD Outdated
srcs = ["common.sh"],
data = [
":all-srcs",
"//hack/lib:all-srcs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually have a sh_library in hack/lib, so //hack/lib is probably a more correct dep here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ixdy
Copy link
Member

ixdy commented Aug 30, 2017

lgtm other than small suggestion (x3)

@mml
Copy link
Contributor Author

mml commented Aug 30, 2017

Oh, wait. Did you mean //hack/lib:lib or just //hack/lib? I'm not clear what the latter would do, but I put the former.

@ixdy
Copy link
Member

ixdy commented Aug 30, 2017

//hack/lib and //hack/lib:lib are basically equivalent - the former implies the latter. either is fine.

maybe squash your commits?

@ixdy
Copy link
Member

ixdy commented Aug 30, 2017

actually, that's false. buildifier (i.e. update-bazel.sh) will simplify //hack/lib:lib to //hack/lib, so you'll need to change that for the verification tests to pass.

@ixdy
Copy link
Member

ixdy commented Aug 30, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 30, 2017
@roberthbailey
Copy link
Contributor

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ixdy, mml, roberthbailey

Associated issue: 51642

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 31, 2017
@cblecker
Copy link
Member

/test all

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@mml
Copy link
Contributor Author

mml commented Aug 31, 2017

/retest #51692

@mml
Copy link
Contributor Author

mml commented Aug 31, 2017

/retest

These just test to see if there is a bash syntax error in these shell
libraries.

For kubernetes#51642
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 31, 2017
@mml mml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 31, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 49971, 51357, 51616, 51649, 51372)

@k8s-github-robot k8s-github-robot merged commit 28d0077 into kubernetes:master Sep 1, 2017
mml added a commit to mml/kubernetes that referenced this pull request Sep 1, 2017
vfreex pushed a commit to vfreex/kubernetes that referenced this pull request Sep 3, 2017
Automatic merge from submit-queue (batch tested with PRs 50579, 50875, 51797, 51807, 51803)

Depend on //cluster/lib instead of :all-srcs.

Cleanup after kubernetes#51649

Bug: kubernetes#51642

```release-note
NONE
```

/assign @ixdy
/assign @roberthbailey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants