Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mountebank v2.0 #9

Merged
merged 17 commits into from
Apr 13, 2019
Merged

mountebank v2.0 #9

merged 17 commits into from
Apr 13, 2019

Conversation

smotes
Copy link
Collaborator

@smotes smotes commented Mar 31, 2019

Major

  • I updated the integration tests to run against a mountebank v2 instance, so we should be ready to start adding new features to the client (see ad1a6d7). However, no actual new v2 features have been added yet.
  • The mountebank v2 API is totally backwards compatible with v1 so I didn't have to adjust the integration tests too much. See http://www.mbtest.org/feed for more details on the backwards compatibility guarantee.

Minor/unrelated

  • I simplified the integration tests by quite a bit by making the assumption that a mountebank instance would already be running at localhost:2525. This allowed me to get rid of all the Docker setup code (see f8c84d6) and remove all the dep vendoring (see 05fcbd2). As a result, you'll need to install and run a local mountebank instance yourself before running the integration tests, directly via NPM or using Docker.
$ npm install --global mountebank@2.0.0
$ mb

-or-

$ docker run -d --rm --name=mountebank -p 2525:2525 -p 8080:8080 -p 8081:8081 andyrbell/mountebank:2.0.0
  • I refactored the internal testutil package into the assert package, to make its intent more clear (see c4e84da).
  • I cleaned up the Makefile a bit (see d80a1b8).

@smotes
Copy link
Collaborator Author

smotes commented Apr 2, 2019

Looks like make errcheck is failing on Go v1.10 due to not supporting that version anymore.

$ make errcheck
error: failed to check packages: unsupported version of go: exit status 2: flag provided but not defined: -compiled

While I do think it's a useful tool, it's a bit of a shame to exclude testing earlier versions of Go just to maintain compatibility. Rather than remove the Go 1.10 checks from CI, I think it would be better to remove the errcheck bit. What do you think?

@alcortesm
Copy link
Contributor

Looks like make errcheck is failing on Go v1.10 due to not supporting that version anymore.

$ make errcheck
error: failed to check packages: unsupported version of go: exit status 2: flag provided but not defined: -compiled

While I do think it's a useful tool, it's a bit of a shame to exclude testing earlier versions of Go just to maintain compatibility. Rather than remove the Go 1.10 checks from CI, I think it would be better to remove the errcheck bit. What do you think?

I think having these checks in your code is a good thing, I use similar checks myself and I find them very helpful. I would not remove them and I don't think you have to sacrifice them to have Go 1.10 compatibility.

The problem here is to attach those checks to particular Go versions. The results of these checks should not change depending on the Go version you are using, by running the checks for several Go versions you are not making your code better, just testing how well supported are those Go versions by the check tools.

I believe these checks should only be run once, in an ad-hoc environment where an specific version of Go and the check tools are pre-installed. You can do this by building a nice docker image with a recent Go version and all testing tools installed. The unit tests on the other hand can be run on Travis for a wide range of Go versions if you want, as that can help people using old versions of Go.

I think that the best way to solve this is to follow this steps:

  1. keep Travis running unit and integration tests on different go versions, that is okay
  2. stop Travis from running the checks (errcheck...) for every Go version
  3. make Travis run the checks only once in a specific environment with recent versions of the tools installed. Also allow developers to do that in the makefile directly (remove the targets from the makefile that install things in developers computers, that is quite harmful if they needed specific versions of those tools for other projects)

@@ -1,25 +0,0 @@
# Gopkg.toml example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is great that you have get rid of the dependencies.

It would be nice if you make this repo a go module, so people can start depending on it using go mod.

@@ -1,29 +1,25 @@
GOPACKAGES := $(shell go list github.com/senseyeio/mbgo/...)
GOPACKAGES := $(shell go list ./...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to my comment above about removing all these checks from here and making it run in a docker, I think this makefile needs some changes:

  • there is no default target, so when you run make it runs make errcheck which is probably not what people wants
  • the integration tests should probably run whatever is required for it to work. If I run it manually without a mountebank instance running, the tests still pass, which is weird as the README explains they rely on some mountebank running.

Copy link
Collaborator Author

@smotes smotes Apr 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I've added a default target to the Makefile which runs the fmt, unit and lint targets -- see commit 6633b7c.
  • I've updated the Makefile to run a new shell script to handle the integration tests, which include spinning up a Docker container for mountebank, running the integration tests, then finally removing the container -- see commit 335c505.
  • It's weird that the tests were passing for you even though an instance wasn't running -- I wasn't able to reproduce that locally. Maybe it was caching?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't know what happened there, I cannot reproduce it either, maybe I didn't notice I had a mountebank instance running.

README.md Outdated
@@ -19,7 +19,9 @@ $ make unit
$ make integration
```

The integration test client points to a local Docker container at port 2525, with the additional ports 8080-8083 exposed for communication with test imposters. Currently tested against a mountebank v1.16.0 instance.
The integration test client expects a version of mountebank running at `localhost:2525`, with the additional ports 8080-8081 exposed for test imposters.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expecting users to have specific software running at specific ports is asking too much IMHO. Maybe running the integration tests in an specific environment build just for that would be a nice idea (docker maybe) to avoid people form having to setup their environment the way the lib wants.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in the Makefile diff and/or commit 335c505.

// tests to assert deep equality between an actual and expected value.
func ExpectEqual(tb testing.TB, actual, expected interface{}) {
func Equals(tb testing.TB, actual, expected interface{}) {
if !reflect.DeepEqual(actual, expected) {
_, file, line, _ := runtime.Caller(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to use of tb.Helper instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 378d3be.

// tests to assert deep equality between an actual and expected value.
func ExpectEqual(tb testing.TB, actual, expected interface{}) {
func Equals(tb testing.TB, actual, expected interface{}) {
if !reflect.DeepEqual(actual, expected) {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, expected, actual)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colors don't work well across different OS.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 378d3be.

@smotes smotes changed the title Smotes/mountebank v2.0 mountebank v2.0 Apr 5, 2019
@smotes
Copy link
Collaborator Author

smotes commented Apr 5, 2019

Looks like make errcheck is failing on Go v1.10 due to not supporting that version anymore.

$ make errcheck
error: failed to check packages: unsupported version of go: exit status 2: flag provided but not defined: -compiled

While I do think it's a useful tool, it's a bit of a shame to exclude testing earlier versions of Go just to maintain compatibility. Rather than remove the Go 1.10 checks from CI, I think it would be better to remove the errcheck bit. What do you think?

I think having these checks in your code is a good thing, I use similar checks myself and I find them very helpful. I would not remove them and I don't think you have to sacrifice them to have Go 1.10 compatibility.

The problem here is to attach those checks to particular Go versions. The results of these checks should not change depending on the Go version you are using, by running the checks for several Go versions you are not making your code better, just testing how well supported are those Go versions by the check tools.

I believe these checks should only be run once, in an ad-hoc environment where an specific version of Go and the check tools are pre-installed. You can do this by building a nice docker image with a recent Go version and all testing tools installed. The unit tests on the other hand can be run on Travis for a wide range of Go versions if you want, as that can help people using old versions of Go.

I think that the best way to solve this is to follow this steps:

1. keep Travis running unit and integration tests on different go versions, that is okay

2. stop Travis from running the checks (errcheck...) for every Go version

3. make Travis run the checks only once in a specific environment with recent versions of the tools installed. Also allow developers to do that in the makefile directly (remove the targets from the makefile that install things in developers computers, that is quite harmful if they needed specific versions of those tools for other projects)

I re-organized the Travis CI file into separate build stages, where the source code analysis stage only uses Go 1.12, whereas the tests will run against all versions. See commit b914ea7.

@alcortesm
Copy link
Contributor

I think your last changes solve all the problems.

I believe travis builds are failing due to golint not being available in the travis environment.

@smotes smotes merged commit a41c6eb into master Apr 13, 2019
@smotes smotes deleted the smotes/mountebank-v2.0 branch July 15, 2019 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants