Skip to content

Commit 5efb65c

Browse files
committed
Update testing documentation with tool installation directions
Fixing a couple of variable declarations that were being complained about by ``make lint``. Edit: Updated the Testing.MD doc to add references to the hack scripts. Addresses: #575
1 parent c1a792c commit 5efb65c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/testing.md

+63
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,66 @@ Run linters test before pushing your commit
3636
```bash
3737
make lint
3838
```
39+
40+
## Using the Hack scripts
41+
42+
The repository contains a ``hack`` directory which has some very useful scripts
43+
for setting up containerized testing environments. It also has Dockerfiles to
44+
allow you to generate images for your own use.
45+
46+
All the scripts accept the ``CONTAINER_RUNTIME`` environment variable with default
47+
of ``podman``. This you can edit to ``docker`` as well.
48+
49+
### Example of running ``golint`` in a Docker container
50+
51+
1. Start by setting the environment variable appropriately
52+
53+
```bash
54+
export CONTAINER_RUNTIME=docker
55+
```
56+
57+
2. From the operator parent dir, you can invoke the hack scripts
58+
59+
```bash
60+
./hack/golint.sh
61+
```
62+
63+
**Note** It's important to be in the operator parent dir because it
64+
contains the ``Makefile`` that is used in running the tests for the
65+
operator. Otherwise, you'll see the following error
66+
67+
```bash
68+
sh: 0: Can't open /go/src/github.com/metal3-io/baremetal-operator/hack/golint.sh
69+
```
70+
71+
3. Upon successful execution, you should see the following output. I already
72+
had all the images available from a previous run, you might see the images
73+
getting downloaded if you're running for the very first time.
74+
75+
```bash
76+
+ IS_CONTAINER=false
77+
+ CONTAINER_RUNTIME=docker
78+
+ [ false != false ]
79+
+ docker run --rm --env IS_CONTAINER=TRUE --volume /home/noor/go/src/github.com/metal3-io/baremetal-operator:/go/src/github.com/metal3-io/baremetal-operator:ro,z\
80+
--entrypoint sh --workdir /go/src/github.com/metal3-io/baremetal-operator\
81+
quay.io/metal3-io/golint:latest /go/src/github.com/metal3-io/baremetal-operator/hack/golint.sh
82+
+ IS_CONTAINER=TRUE
83+
+ CONTAINER_RUNTIME=podman
84+
+ [ TRUE != false ]
85+
+ export XDG_CACHE_HOME=/tmp/.cache
86+
+ make lint
87+
which golint 2>&1 >/dev/null || make OPATH/bin/golint
88+
find ./pkg ./cmd -type f -name \*.go |grep -v zz_ | xargs -L1 golint -set_exit_status
89+
```
90+
91+
## Getting the latest tooling
92+
93+
For testing without the hack scripts, make sure you install the latest
94+
development tools using ``go get``, e-g
95+
96+
```bash
97+
go get golang.org/x/lint/golint
98+
```
99+
100+
This ensures that the linters you have locally and the ones running in the CI
101+
are matched and helps avoid inconsistencies. Happy coding!

0 commit comments

Comments
 (0)