All Projects β†’ omeid β†’ conex

omeid / conex

Licence: MIT License
Conex integrates Docker with testing package so you can easily run your integration tests with containers.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to conex

Mockttp
Powerful friendly HTTP mock server & proxy
Stars: ✭ 346 (+337.97%)
Mutual labels:  integration-testing, testing-tools
Gest
πŸ‘¨β€πŸ’» A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (+37.97%)
Mutual labels:  integration-testing, testing-tools
Hermione
Browser test runner based on mocha and wdio
Stars: ✭ 454 (+474.68%)
Mutual labels:  integration-testing, testing-tools
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (-32.91%)
Mutual labels:  integration-testing, testing-tools
Cuprite
Headless Chrome/Chromium driver for Capybara
Stars: ✭ 743 (+840.51%)
Mutual labels:  integration-testing, testing-tools
kheera-testrunner-android
BDD Framework for Android
Stars: ✭ 18 (-77.22%)
Mutual labels:  integration-testing, testing-tools
gmock-xcode
Xcode integration for GoogleMock through XCTest
Stars: ✭ 18 (-77.22%)
Mutual labels:  testing-tools
mock-inspect
Mocks network requests and allows you to make assertions about how these requests happened. Supports auto-mocking of graphQL requests given a valid schema.
Stars: ✭ 19 (-75.95%)
Mutual labels:  testing-tools
StrictCheck
Keep your laziness in check!
Stars: ✭ 28 (-64.56%)
Mutual labels:  testing-tools
servirtium-java
Service Virtualized HTTP - to help service test automation stay fast and consistent
Stars: ✭ 16 (-79.75%)
Mutual labels:  testing-tools
what-vpn
Identify servers running various SSL VPNs based on protocol-specific behaviors
Stars: ✭ 24 (-69.62%)
Mutual labels:  testing-tools
pytest-djangoapp
Nice pytest plugin to help you with Django pluggable application testing.
Stars: ✭ 35 (-55.7%)
Mutual labels:  testing-tools
testkube
☸️ Kubernetes-native framework for test definition and execution
Stars: ✭ 172 (+117.72%)
Mutual labels:  testing-tools
page-modeller
βš™οΈ Browser DevTools extension for modelling web pages for automation.
Stars: ✭ 66 (-16.46%)
Mutual labels:  testing-tools
leancheck
enumerative property-based testing for Haskell
Stars: ✭ 38 (-51.9%)
Mutual labels:  testing-tools
w3c-webdriver
W3C WebDriver JavaScript Client
Stars: ✭ 28 (-64.56%)
Mutual labels:  integration-testing
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+372.15%)
Mutual labels:  testing-tools
JUnitPerf
API performance testing framework built using JUnit
Stars: ✭ 48 (-39.24%)
Mutual labels:  testing-tools
cypress-plugin-stripe-elements
A small Cypress plugin that assists you in filling in Stripe Elements inputs
Stars: ✭ 22 (-72.15%)
Mutual labels:  testing-tools
QuickStarter
Quick nodejs (Express) + docker + mongodb + JEST(testing) setup.
Stars: ✭ 12 (-84.81%)
Mutual labels:  integration-testing

Conex GoDoc Build Status Go Report Card

Conex integrates Go testing with Docker so you can easily run your integration tests and benchmarks.

Yes, we did hear you like integrations.

Why?

Integration tests are very good value, they're easy to write and help you catch bugs in a more realistic environment and with most every service and database avaliable as a Docker Container, docker is a great option to run your service dependencies in a clear state. Conex is here to make it simpler by taking care of the following tasks:

  • starting containers
  • automatically creating uniqe names to avoid conflicts
  • deleting containers
  • pull or check images before running tests
  • Wait for a service (tcp, udp) port to accept connections
  • Expose ports

On top of that, Conex providers a driver convention to simplify code reuse across projects.

How?

To use conex, we will leverage TestMain, this will allow us a starting point to connect to docker, pull all the dependent images and only then run the tests.

Simpley call conex.Run(m) where you would run m.Run().

func TestMain(m *testing.M) {
  // If you're planing to use conex.Box directly without
  // using a driver, you can pass your required images
  // after m to conex.Run.
  os.Exit(conex.Run(m))
}

In our tests, we will use driver packages, these packages register their required image with conex and provide you with a native client and take cares of requesting a container from conex.

Here is an example using redis:

func testPing(t *testing.T) {
  redisDb: = 0
  client, container := redis.Box(t, redisDb)
  defer container.Drop() // Return the container.

  // here we can simply use client which is a go-redis
  // client.
}

Boxes

You can find find drivers/box packages for redis, mysql, postgresql, rethinkdb, and many more on github.com/conex.

Example

Here is a complete example using a simple Echo service.

You can create many containers and different services as you want, you can also run multiple tests in parallel without conflict, conex creates the containers with uniqe names that consist of the test id, package path, test name, container, and an ordinal index starting from 0. This avoids container name conflicts across the board.

package example_test

import (
  "os"
  "testing"

  "github.com/omeid/conex"
  "github.com/omeid/conex/echo"
  echolib "github.com/omeid/echo"
)

func TestMain(m *testing.M) {
  os.Exit(conex.Run(m))
}

func TestEcho(t *testing.T) {
  reverse := true

  e, container := echo.Box(t, reverse)
  defer container.Drop() // Return the container.

  say := "hello"
  expect := say
  if reverse {
    expect = echolib.Reverse(say)
  }

  reply, err := e.Say(say)

  if err != nil {
    t.Fatal(err)
  }

  if reply != expect {
    t.Fatalf("\nSaid: %s\nExpected: %s\nGot:      %s\n", say, expect, reply)
  }

}

// You can also use containers in benchmarks!
func BenchmarkEcho(b *testing.B) {

	reverse := false
	say := "hello"
	expect := say

	e, c := echo.Box(b, reverse)
	defer c.Drop()

	for n := 0; n < b.N; n++ {

		reply, err := e.Say(say)

		if err != nil {
			b.Fatal(err)
		}

		if reply != expect {
			b.Fatalf("\nSaid: %s\nExpected: %s\nGot:      %s\n", say, expect, reply)
		}
	}
}

And running tests will yield:

$ go test -v
2017/04/17 22:13:05 
=== conex: Pulling Images
--- Pulling omeid/echo:http (1 of 1)
http: Pulling from omeid/echo
627beaf3eaaf: Already exists 
8800e3417eb1: Already exists 
b6acb96fee14: Already exists 
66be5afddf19: Already exists 
8ca17cdcfc93: Already exists 
792cf0844f5e: Already exists 
26601152322c: Pull complete 
2cb3c6a6d3ee: Pull complete 
Digest: sha256:f6968275ab031d91a3c37e8a9f65b961b5a3df850a90fe4551ecb4724ab3b0a7
Status: Downloaded newer image for omeid/echo:http
=== conex: Pulling Done
2017/04/17 22:13:38 
2017/04/17 22:13:38 
=== conex: Starting your tests.
=== RUN   TestEcho
--- PASS: TestEcho (0.55s)
      conex.go:11: creating (omeid/echo:http: -reverse) as conex_508151185_test-TestEcho-omeid_echo.http_0
      conex.go:11: started (omeid/echo:http: -reverse) as conex_508151185_test-TestEcho-omeid_echo.http_0
PASS
ok    test  33.753s

Drivers Packages

Conex drivers are simple packages that follow a convention to provide a simple interface to the underlying service run on the container. So the user doesn't have to think about containers but the service in their tests.

First, define an image attribute for your package that users can change and register it with conex.

// Image to use for the box.
var Image = "redis:alpine"

func init() {
  conex.Require(func() string { return Image })
}

Then request a container with the required image from conex and setup a client that is connected to the container you created. Return the client and the container.

// Box returns an connect to an echo container based on
// your provided tags.
func Box(t testing.TB, optionally SomeOptions) (your.Client, conex.Container)) {

  conf := &conex.Config{
    Image: Image,
    // Here you may set other options based
    // on the options passed to Box.
  }

  c, con := conex.Box(t, conf)

  opt := &your.Options{
    Addr: c.Address(),
    magic: optionally.SomeMagic,
  }

  client, err := redis.NewClient(opt)

  if err != nil {
    t.Fatal(err)
  }

  return client, con
}

Caveat

Only native docker is support, so Docker for Mac and Docker Machine in general is not supported because of how port forwarding and port maping works.

Is it good?

Yes.

LICENSE

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].