Contributing to Mattermost

go Hacktoberfest

What is Mattermost?

From their site:

Mattermost is a flexible, open source messaging platform
that enables secure team collaboration

So think of Mattermost as an open source Slack alternative. It is also bundled with GitLab on premise Omnibus installations.

What do I want to achieve?

While trying to participate in Hacktoberfest 2019 I chose a migration issue for Mattermost as my first target for a PR:

Migrate tests from “model/system_test.go” to use testify

What is this post about

This post is about my experience about contributing (or failing to do so) to Mattermost.

Contributing

Getting in touch

After I found the issue I want to work with I joined the Mattermost build server and asked to be assigned by commenting on the issue. The response was fast and due to this I felt already welcome.

Setup

I started to setup the development environment according to the article Developer Setup -> ArchLinux. This is pretty straight forward and works as described.

To test my setup I intended to run the existing tests as a baseline. Unfortunately this did not work out of the box:

go: willnorris.com/go/imageproxy@v0.9.0 requires
    cloud.google.com/go@v0.37.1 requires
    go.opencensus.io@v0.19.1 requires
    google.golang.org/genproto@v0.0.0-20181219182458-5a97ab628bfb requires
    google.golang.org/grpc@v1.16.0 requires
    github.com/golang/lint@v0.0.0-20190227174305-8f45f776aaf1: invalid pseudo-version: does not match version-control timestamp     (2018-12-17T17:45:47Z)

As a matter of fact this is not an error in Mattermost’s code base but in the way Go 1.13 handles timestamp validation in Go modules. So temporarily reverting back to Go 1.12 helped me out. Luckily I deploy Go on my machine with Ansible with my own role and a switch between versions of gGo is a matter of a small playbook run.

Running the whole tests takes some time and it turned out running the complete suite with a developer setup for the server only will not work.

As my contribution is related to the model package I sitched to the model subdirectory and ran go test ./... -v:

=== RUN   TestAccessJson
--- PASS: TestAccessJson (0.00s)
=== RUN   TestAccessIsValid
--- PASS: TestAccessIsValid (0.00s)
=== RUN   TestAnalyticsRowJson
--- PASS: TestAnalyticsRowJson (0.00s)
=== RUN   TestAnalyticsRowsJson

...

--- PASS: TestConfigDefaults (0.01s)
    --- PASS: TestConfigDefaults/somewhere_nil_when_uninitialized (0.00s)
        utils_test.go:725: config.ServiceSettings.SiteURL was nil
    --- PASS: TestConfigDefaults/nowhere_nil_when_initialized (0.00s)
    --- PASS: TestConfigDefaults/nowhere_nil_when_partially_initialized (0.01s)
PASS
ok      github.com/mattermost/mattermost-server/model   (cached)
?       github.com/mattermost/mattermost-server/model/gitlab    [no test files]

As of now, I had a valid base for my implementation.

Implementation

The first implementation was easy going: removing three lines, adding two. So instead of this:

if result.Name != "test" {
  t.Fatal("Ids do not match")
}

the code is now (as the time of the writing):

require.Equal(t, "test", result.Name, "ids do not match")

And yay: the tests still passed! To test if they break, I temporarily compared to test2 and it failed as expected.

Pull Request!

Now that the test still works I created a PR to have my changes integrated to Mattermost.

After the reviews my PR was merged and I participated in making an open source software a little bit better.