Posts Categorized “programming”

MacBook Pro retina display resolution in Ubuntu

Here is a quick post on how I fixed my retina resolution on ubuntu.

Today I installed ubuntu 13.04 on my MacBook Pro Retina (10,1). Everything worked fine out of the box, but ubuntu has set the display resolution to 2880x1800. Although I looks pretty sexy to have such a high resolution, I thought it was a bit to much. I played a bit with different settings and I found that a scale factor of 0.6x0.6 works the best. Here is a command to change it:

xrandr --output eDP-2 --scale .6x.6

Checking code coverage on wercker with gocov

Code coverage can be an important metric to watch. It gives you insight in which parts of your code are covered well by tests and which might need some extra attention. In this post I will explain how I leverage gocov in adding test coverage reports to the build pipeline of one of my go projects.

Executing tests with gocov

To measure test coverage in Go we can use gocov created by Andrew Wilkins. It has a test command that executes the test with the default go test test runner and generates the coverage details in json format. The gocov test command respects the go test command and still prints output from it to the console. Here is an example of a script step that runs the tests for all packages and subpackages of the working directory and writes the coverage results to a file called coverage.json:

- script:
    name: Test
    code: |-
        # Get gocov package
        go get

        # Execute actual tests and store coverage result
        gocov test ./... > coverage.json

Next to the coverage.json that will be created, it writes the following output:

ok 0.070s
ok  0.023s
ok 0.022s
ok 0.012s
?  [no test files]
ok  0.021s
? [no test files]
? [no test files]

You can see the actual step result on wercker: go-cqrs / 6c8cd61 / test.

Generating the report

The coverage.json created by the previous step can now be used as input for the report command. This commands generates a textual report based on the coverage.json. It makes sence to do this in a seperate step to seperate the test output and the coverage output. Here is an example of a script step that executes the gocov report command:

  - script:
        name: Coverage
        code: gocov report coverage.json

This step will write the following output:         InitLogging            100.00% (3/3)  EventStore.ReadStream   0.00% (0/27)  EventStore.WriteStream  0.00% (0/22)  downloadEvent           0.00% (0/13)  processFeed             0.00% (0/9)  linksToMap              0.00% (0/4)  DailEventStore          0.00% (0/1)                ----------------------  3.80% (3/79)  InitLogging   100.00% (3/3)         -----------   100.00% (3/3)

You can see the actual step result on wercker: go-cqrs / 6c8cd61 / coverage.

Writing to the artifact dir

The coverage.json can also be used to create a nice self sufficient html report. We can use gocov-html tool for this. Here is how I enchanced the previous step and added html reporting that is stored in the artifact directory.

- script:
    name: Coverage
    code: |-
        go get
        gocov report coverage.json
        gocov-html coverage.json > $WERCKER_REPORT_ARTIFACTS_DIR/coverage.html

When this step succeeds you can download the artifacts package and open coverage.html.

coverage report

What is next

Now wercker gives insight in your test coverage for your golang projects. The next step is to use the coverage as a number to pass or fail the build. Stay tuned for an update where I will create a step to do this.

Clean up your docker containers

Working with docker is great, but sometimes I feel the need to cleanup my containers. Currently docker has no easy way for doing this. So let me share some commands with you I use frequently.

There has been some talk on Github about a docker clean command. If you are interested I suggest you to watch this issue: Implement a 'clean' command. Until this feature is released, you can use one of the following command to clean up all your containers.

Remove all containers

# WARNING: This will remove all your docker containers!
docker ps -a | tail -n +2 | awk '{print $1}' | xargs docker rm

Remove containers older than a week

# WARNING: This will remove all docker containers older than one week!
docker ps -a | grep 'week ago' | awk '{print $1}' | xargs docker rm

Remove containers from specific image

# WARNING: This will remove all containers from matching image(s)
docker ps -a | awk '{$2 ~ /my-image-name/} {print $1}' | xargs docker rm