What is GoMock?

Overview of a mocking framework for Go with code examples
16 August 2017   1750

GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testingpackage, but can be used in other contexts too.

Installation

Run these commands to install the gomock package and the mockgen tool:

go get github.com/golang/mock/gomock
go get github.com/golang/mock/mockgen

Four steps of GoMock usage:

  1. Use mockgen to generate a mock for the interface you wish to mock.
  2. In your test, create an instance of gomock.Controller and pass it to your mock object’s constructor to obtain a mock object.
  3. Call EXPECT() on your mocks to set up their expectations and return values
  4. Call Finish() on the mock controller to assert the mock’s expectations

mockgen has two modes of operation: source and reflect. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports and -aux_files.

Example:

mockgen -source=foo.go [other options]

Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols.

Example:

mockgen database/sql/driver Conn,Driver

Learn more at GiHub and with tutorial

Brigade launched

Event-driven scripting tool for Kubernetes released by Microsoft
31 October 2017   453

Microsoft has unveiled its new Open Source development for the needs of DevOps, a Brigade utility designed to run scripts that are executed on a Kubernetes cluster on an event.

The Brigade utility was created by former employees of Deis, a company that Microsoft bought earlier this year. Deis was working on Kubernetes, Helm and Draft. The purpose of Brigade is to "script simple and complex workflows using JavaScript." The solution allows to associate containers by running them sequentially or in parallel and invoking scripts based on time, events in GitHub (also supported by "DockerHub and other popular web services"), push operations in Docker or other triggers. Readme of the project describes it as "a tool for creating pipelines for Kubernetes".

Brigade architecture
Brigade architecture 

Brigade is written in Go and TypeScript / JavaScript, it functions as a service inside Kubernetes. The job (task) in Brigade is a JavaScript script that is interpreted by the product service, which leads to the creation of the necessary resources in Kubernetes. Next, Brigade expects events and performs the corresponding task trigger. It is assumed that the new solution is well suited for the tasks of continuous integration and delivery of applications (CI / CD), tk. simplifies automated testing, assembly of artifacts and releases, management of software deployment.

Check GitHub for more information.