Merge pull request #16 from arthurbarr/master

Updates to code coverage and Explorer
This commit is contained in:
Arthur Barr
2017-11-13 14:57:19 +00:00
committed by GitHub
7 changed files with 69 additions and 20 deletions

View File

@@ -12,11 +12,19 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
FROM mqadvanced:latest-x86_64 # Build stage to build Go code
FROM golang:1.9 as builder
WORKDIR /go/src/github.com/ibm-messaging/mq-container/
COPY cmd/ ./cmd
COPY pkg/ ./pkg
COPY vendor/ ./vendor
RUN go test -c -covermode=count ./cmd/runmqserver
FROM mq-advancedserver:latest-x86_64
# Copy in the version of the code instrumented for code coverage # Copy in the version of the code instrumented for code coverage
COPY build/runmqserver.test /usr/local/bin/runmqserver.test COPY --from=builder /go/src/github.com/ibm-messaging/mq-container/runmqserver.test /usr/local/bin/
RUN chmod +x /usr/local/bin/runmqserver.test \ RUN chmod +x /usr/local/bin/runmqserver.test \
&& mkdir -p /var/coverage/ && mkdir -p /var/coverage/
ENTRYPOINT ["runmqserver.test", "-test", "-test.coverprofile", "/var/coverage/coverage.cov"] ENTRYPOINT ["runmqserver.test", "-test", "-test.coverprofile", "/var/coverage/container.cov"]

View File

@@ -28,6 +28,7 @@ DOCKER_FULL_ADVANCEDSERVER = $(DOCKER_REPO_ADVANCEDSERVER):$(DOCKER_TAG)
TEST_OPTS_DOCKER ?= TEST_OPTS_DOCKER ?=
# Options to `go test` for the Kubernetes tests # Options to `go test` for the Kubernetes tests
TEST_OPTS_KUBERNETES ?= TEST_OPTS_KUBERNETES ?=
TEST_IMAGE ?= $(DOCKER_FULL_ADVANCEDSERVER)
.PHONY: default .PHONY: default
default: build-devserver test default: build-devserver test
@@ -79,6 +80,16 @@ test-devserver:
cd pkg/name && go test cd pkg/name && go test
cd test/docker && TEST_IMAGE=$(DOCKER_FULL_DEVSERVER) go test cd test/docker && TEST_IMAGE=$(DOCKER_FULL_DEVSERVER) go test
.PHONY: test-advancedserver-cover
test-advancedserver-cover:
cd pkg/name && go test
rm -f ./test/docker/coverage/*.cov
rm -f ./coverage/docker.*
cd test/docker && TEST_IMAGE=$(DOCKER_REPO_ADVANCEDSERVER):cover go test $(TEST_OPTS_DOCKER)
echo 'mode: count' > ./coverage/docker.cov
tail -q -n +2 ./test/docker/coverage/*.cov >> ./coverage/docker.cov
go tool cover -html=./coverage/docker.cov -o ./coverage/docker.html
.PHONY: test-kubernetes-devserver .PHONY: test-kubernetes-devserver
test-kubernetes-devserver: test-kubernetes-devserver:
$(call test-kubernetes,$(DOCKER_REPO_DEVSERVER),$(DOCKER_TAG),"../../charts/ibm-mqadvanced-server-dev") $(call test-kubernetes,$(DOCKER_REPO_DEVSERVER),$(DOCKER_TAG),"../../charts/ibm-mqadvanced-server-dev")
@@ -148,8 +159,8 @@ build-devserver: downloads/mqadv_dev903_ubuntu_x86-64.tar.gz
# $(DOCKER) tag mq-server:latest-$(DOCKER_TAG_ARCH) mq-server:9.0.3-$(DOCKER_TAG_ARCH) # $(DOCKER) tag mq-server:latest-$(DOCKER_TAG_ARCH) mq-server:9.0.3-$(DOCKER_TAG_ARCH)
.PHONY: build-advancedserver-cover .PHONY: build-advancedserver-cover
build-advancedserver-cover: build-advanced-server build-cov build-advancedserver-cover:
$(DOCKER) build -t mq-advancedserver:cover -f Dockerfile-server.cover . $(DOCKER) build -t $(DOCKER_REPO_ADVANCEDSERVER):cover -f Dockerfile-server.cover .
# .PHONY: build-web # .PHONY: build-web
# build-web: build downloads/CNJR7ML.tar.gz # build-web: build downloads/CNJR7ML.tar.gz

View File

@@ -4,7 +4,7 @@
You need to ensure you have the following tools installed: You need to ensure you have the following tools installed:
* [Docker](https://www.docker.com/) * [Docker](https://www.docker.com/)
* [Go](https://golang.org/) * [Go](https://golang.org/) - only needed for running the tests
* [Glide](https://glide.sh/) * [Glide](https://glide.sh/)
* [dep](https://github.com/golang/dep) (official Go dependency management tool) * [dep](https://github.com/golang/dep) (official Go dependency management tool)
* make * make
@@ -21,10 +21,27 @@ There are three main sets of tests:
### Running the tests ### Running the tests
The unit and Docker tests can be run locally. For example: The unit and Docker tests can be run locally. For example:
```bash ```
make test-devserver make test-devserver
``` ```
or:
```
make test-advancedserver
```
### Running the tests with code coverage
You can produce code coverage results from the Docker tests by running the following:
```
make build-advancedserver-cover
make test-advancedserver-cover
```
In order to generate code coverage metrics from the Docker tests, the build step creates a new Docker image with an instrumented version of the code. Each test is then run individually, producing a coverage report each under `test/docker/coverage/`. These individual reports are then combined. The combined report is written to the `coverage` directory.
### Running the Kubernetes tests ### Running the Kubernetes tests
For the Kubernetes tests, you need to have built the Docker image, and pushed it to the registry used by your Kubernetes cluster. Most of the configuration used by the tests is picked up from your `kubectl` configuration, but you will typically need to specify the image details. For example: For the Kubernetes tests, you need to have built the Docker image, and pushed it to the registry used by your Kubernetes cluster. Most of the configuration used by the tests is picked up from your `kubectl` configuration, but you will typically need to specify the image details. For example:

View File

@@ -1,14 +1,19 @@
Docker for Mac Docker for Mac
-------------- --------------
Steps to build a Docker image containing IBM MQ Explorer:
1. Download and extract the code from [GitHub](https://codeload.github.com/ibm-messaging/mq-container/zip/master), or run the following command: `git clone https://github.com/ibm-messaging/mq-container`
2. Open a Terminal window in the `mq-container` directory
3. Run `docker build -t mq-explorer -f ./incubating/mq-explorer/Dockerfile .`
1. Install XQuartz. Version 2.7.10 works, but V2.7.11 doesn't seem to. Steps to prepare your Mac with XQuartz:
1. Install XQuartz. Version 2.7.10 works, but V2.7.11 doesn't seem to (see [this thread](https://stackoverflow.com/questions/38686932/how-to-forward-docker-for-mac-to-x11))
2. Run XQuartz 2. Run XQuartz
3. Open the XQuartz "Preferences" menu, go to the "Security" tab and enable "Allow connections from network clients" 3. Open the XQuartz "Preferences" menu, go to the "Security" tab and enable "Allow connections from network clients"
4. Add your IP address to the list of allowed hosts: `xhost + $(ipconfig getifaddr en0)`
5. Run MQ Explorer: `docker run -e DISPLAY=$(ipconfig getifaddr en0):0 -v /tmp/.X11-unix:/tmp/.X11-unix -u 0 -ti mq-explorer`
https://stackoverflow.com/questions/38686932/how-to-forward-docker-for-mac-to-x11 Steps to run IBM MQ Explorer:
1. Add your IP address to the list of allowed hosts: `xhost + $(ipconfig getifaddr en0)`
2. Run MQ Explorer: `docker run -e DISPLAY=$(ipconfig getifaddr en0):0 -v /tmp/.X11-unix:/tmp/.X11-unix -u 0 -ti mq-explorer`
docker run -e DISPLAY=docker.for.mac.localhost:0 -v /tmp/.X11-unix:/tmp/.X11-unix -u 0 -ti mq-explorer
Use DISPLAY=docker.for.mac.localhost:0 ???

View File

@@ -123,7 +123,6 @@ func TestWithVolume(t *testing.T) {
hostConfig := container.HostConfig{ hostConfig := container.HostConfig{
Binds: []string{ Binds: []string{
coverageBind(t), coverageBind(t),
//"coverage:/var/coverage",
vol.Name + ":/mnt/mqm", vol.Name + ":/mnt/mqm",
}, },
} }

View File

@@ -41,12 +41,18 @@ func imageName() string {
return image return image
} }
func coverageBind(t *testing.T) string { // coverageDir returns the host directory to use for code coverage data
func coverageDir(t *testing.T) string {
dir, err := os.Getwd() dir, err := os.Getwd()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return filepath.Join(dir, "coverage") + ":/var/coverage" return filepath.Join(dir, "coverage")
}
// coverageBind returns a string to use to add a bind-mounted directory for code coverage data
func coverageBind(t *testing.T) string {
return coverageDir(t) + ":/var/coverage"
} }
func cleanContainer(t *testing.T, cli *client.Client, ID string) { func cleanContainer(t *testing.T, cli *client.Client, ID string) {
@@ -62,10 +68,8 @@ func cleanContainer(t *testing.T, cli *client.Client, ID string) {
// Just log the error and continue // Just log the error and continue
t.Log(err) t.Log(err)
} }
//waitForContainer(t, cli, ID, 20, container.WaitConditionNotRunning) // If a code coverage file has been generated, then rename it to match the test name
os.Rename(filepath.Join(coverageDir(t), "container.cov"), filepath.Join(coverageDir(t), t.Name()+".cov"))
// TODO: This is probably no longer necessary
time.Sleep(20 * time.Second)
// Log the container output for any container we're about to delete // Log the container output for any container we're about to delete
t.Logf("Console log from container %v:\n%v", ID, inspectLogs(t, cli, ID)) t.Logf("Console log from container %v:\n%v", ID, inspectLogs(t, cli, ID))
@@ -87,6 +91,8 @@ func runContainer(t *testing.T, cli *client.Client, containerConfig *container.C
if containerConfig.Image == "" { if containerConfig.Image == "" {
containerConfig.Image = imageName() containerConfig.Image = imageName()
} }
// if coverage
containerConfig.Env = append(containerConfig.Env, "COVERAGE_FILE="+t.Name()+".cov")
hostConfig := container.HostConfig{ hostConfig := container.HostConfig{
PortBindings: nat.PortMap{ PortBindings: nat.PortMap{
"1414/tcp": []nat.PortBinding{ "1414/tcp": []nat.PortBinding{
@@ -96,6 +102,9 @@ func runContainer(t *testing.T, cli *client.Client, containerConfig *container.C
}, },
}, },
}, },
Binds: []string{
coverageBind(t),
},
} }
networkingConfig := network.NetworkingConfig{} networkingConfig := network.NetworkingConfig{}
t.Logf("Running container (%s)", containerConfig.Image) t.Logf("Running container (%s)", containerConfig.Image)