All Projects â†’ beme â†’ Abide

beme / Abide

Licence: apache-2.0
📸 A Go testing utility for http response snapshots.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Abide

Zrepl
One-stop ZFS backup & replication solution
Stars: ✭ 327 (+360.56%)
Mutual labels:  snapshot
Scaleway Cli
Command Line Interface for Scaleway
Stars: ✭ 654 (+821.13%)
Mutual labels:  snapshot
Pm2.5 Idw Map
PM2.5 IDW Map from PM2.5 open data portal
Stars: ✭ 14 (-80.28%)
Mutual labels:  snapshot
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (+590.14%)
Mutual labels:  snapshot
Redux Ship
Side effects with snapshots for Redux.
Stars: ✭ 615 (+766.2%)
Mutual labels:  snapshot
Mobx State Tree
Full-featured reactive state management without the boilerplate
Stars: ✭ 6,317 (+8797.18%)
Mutual labels:  snapshot
Ipcam View
MJPEG video streaming on Android
Stars: ✭ 292 (+311.27%)
Mutual labels:  snapshot
Moosefs
MooseFS – Open Source, Petabyte, Fault-Tolerant, Highly Performing, Scalable Network Distributed File System (Software-Defined Storage)
Stars: ✭ 1,025 (+1343.66%)
Mutual labels:  snapshot
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (+798.59%)
Mutual labels:  snapshot
Preact Jest Snapshot Test Boilerplate
🚀 Test Preact components using Jest snapshots
Stars: ✭ 24 (-66.2%)
Mutual labels:  snapshot
Unix History Repo
Continuous Unix commit history from 1970 until today
Stars: ✭ 4,851 (+6732.39%)
Mutual labels:  snapshot
Btrbk
Tool for creating snapshots and remote backups of btrfs subvolumes
Stars: ✭ 605 (+752.11%)
Mutual labels:  snapshot
Playbook Ios
📘A library for isolated developing UI components and automatically taking snapshots of them.
Stars: ✭ 830 (+1069.01%)
Mutual labels:  snapshot
Gwt Material
A Google Material Design wrapper for GWT
Stars: ✭ 386 (+443.66%)
Mutual labels:  snapshot
Collectionviewpaginglayout
a simple but highly customizable paging layout for UICollectionView.
Stars: ✭ 947 (+1233.8%)
Mutual labels:  snapshot
Singlefile
Web Extension for Firefox/Chrome/MS Edge and CLI tool to save a faithful copy of an entire web page in a single HTML file
Stars: ✭ 4,417 (+6121.13%)
Mutual labels:  snapshot
Polo
Polo travels through your database and creates sample snapshots so you can work with real world data in development.
Stars: ✭ 695 (+878.87%)
Mutual labels:  snapshot
Backintime
Back In Time - A simple backup tool for Linux
Stars: ✭ 1,066 (+1401.41%)
Mutual labels:  snapshot
Jsdom Screenshot
📸 Take screenshots of jsdom with puppeteer
Stars: ✭ 39 (-45.07%)
Mutual labels:  snapshot
Concise Ipython Notebooks For Deep Learning
Ipython Notebooks for solving problems like classification, segmentation, generation using latest Deep learning algorithms on different publicly available text and image data-sets.
Stars: ✭ 23 (-67.61%)
Mutual labels:  snapshot

abide

A testing utility for http response snapshots. Inspired by Jest.

Build Status GoDoc

Usage

  1. Include abide in your project.
import "github.com/beme/abide"
  1. Within your test function, capture the response to an http request, set a unique identifier, and assert.
func TestFunction(t *testing.T) {
  req := httptest.NewRequest("GET", "http://example.com/", nil)
  w := httptest.NewRecorder()
  exampleHandler(w, req)
  res := w.Result()
  abide.AssertHTTPResponse(t, "example route", res)
}
  1. Run your tests.
$ go test -v
  1. If the output of your http response does not equal the existing snapshot, the difference will be printed in the test output. If this change was intentional, the snapshot can be updated by including the -u flag.
$ go test -v -- -u

Any snapshots created/updated will be located in package/__snapshots__.

  1. Cleanup

To ensure only the snapshots in-use are included, add the following to TestMain. If your application does not have one yet, you can read about TestMain usage here.

func TestMain(m *testing.M) {
  exit := m.Run()
  abide.Cleanup()
  os.Exit(exit)
}

Once included, if the update -u flag is used when running tests, any snapshot that is no longer in use will be removed. Note: if a single test is run, pruning will not occur.

Snapshots

A snapshot is essentially a lock file for an http response. Instead of having to manually compare every aspect of an http response to it's expected value, it can be automatically generated and used for matching in subsequent testing.

Here's an example snapshot:

/* snapshot: example route */
HTTP/1.1 200 OK
Connection: close
Content-Type: application/json

{
  "key": "value"
}

When working with snapshots in a git repository, you could face some end line replacements that can cause comparison issues (warning: CRLF will be replaced by LF in ...). To solve that just configure the snapshots as binary files in .gitattributes of your project root:

*.snapshot binary

abide also supports testing outside of http responses, by providing an Assert(*testing.T, string, Assertable) method which will create snapshots for any type that implements String() string.

Example

See /example for the usage of abide in a basic web server. To run tests, simply $ go test -v

Config

In some cases, attributes in a JSON response can by dynamic (e.g unique id's, dates, etc.), which can disrupt snapshot testing. To resolve this, an abide.json file config can be included to override values with defaults. Consider the config in the supplied example project:

{
  "defaults": {
    "Etag": "default-etag-value",
    "updated_at": 0,
    "foo": "foobar"
  }
}

When used with AssertHTTPResponse, for any response with Content-Type: application/json, the key-value pairs in defaults will be used to override the JSON response, allowing for consistent snapshot testing. Any HTTP headers will also be override for key matches in defaults.

Using custom __snapshot__ directory

To write snapshots to a directory other than the default __snapshot__, adjust abide.SnapshotDir before any call to an Assert function. See example/models package for a working example

func init() {
  abide.SnapshotDir = "testdata"
}
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].