GithubHelp home page GithubHelp logo

go-matcha's Introduction

go-matcha

Features

Data formats

There are assertion methods for both JSON and XML.

Note that XML matching is currently fairly naïve in that it doesn't read XML schemas or check attributes. One particular limitation of this is that if you are expecting an array of elements back, and in the actual XML there is only one element in the array, the assertion will fail (since in the absence of a schema it is impossible to know if it is an array with one element or just a single element).

Capturing values from the response

If you define a field with a capture tag then that field will be captured from the response. This is useful for more complex assertions.

For example, the following field would be captured as 'count':

Count    float64 `capture:"count"`

Captured values come back as a map of slices (type = matcha.CapturedValues). This is so that multiple values can be captured. For example, if we are expecting a list of objects, each with a "date" field, then capturedValues["date"] will be a list of dates, one for each object.

Regex pattern matching

You can use a pattern tag on a string field if you are expecting to it to match a given regex.

For example if you have a date field such as 2016-09-12 then you could use the following field definition:

Date    string `pattern:"^[0-9]{4}-[0-9]{2}-[0-9]{2}"`

Note that it is not possible to use "complex" string literals in Go struct tags, therefore it is not possible to use some characters, such as \.

go-matcha's People

Contributors

rossgray avatar nicwest avatar matt-allpress avatar

Watchers

James Cloos avatar ghimire avatar Devan Patel avatar Bob Walters avatar Konrad Wąsowicz avatar maurer2 avatar Electra Coury avatar Oleksandr Gorbunov avatar Sam Holmes avatar Charles Lewis avatar Steven Gouws avatar Brian Call avatar  avatar Lewis Vail avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.