• Stars
    star
    277
  • Rank 148,875 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

API testing framework inspired by frisby-js

frisby

Build Status GoDoc GitHub release

REST API testing framework inspired by frisby-js, written in Go

Proposals

I'm starting to work on frisby again with the following ideas:

  1. Read specification files
  • pyresttest
  • frisby.js
  • swagger spec
  • other?
  1. Use as a load tester
  • like Locust.io
  • distributed
  1. UI
  • Dashboard
  • Analytics
  • Reports
  • Manage multiple instances
  1. Backend
  • master/minions
  • db for analytics
  • api for UI / clients Goa
  • federation of minion groups?

Please comment on any issues or PRs related to these proposals. If you don't see an issue, PR, or idea; definitely add it!

Installation

go get -u github.com/verdverm/frisby

Basic Usage

First create a Frisby object:

// create an object with a given name (used in the report)
F := frisby.Create("Test successful user login").
    Get("https://golang.org")

Add any pre-flight data

F.SetHeader("Content-Type": "application/json").
	SetHeader("Accept", "application/json, text/plain, */*").
	SetJson([]string{"item1", "item2", "item3"})

There is also a Global object for setting repeated Pre-flight options.

frisby.Global.BasicAuth("username", "password").
	SetHeader("Authorization", "Bearer " + TOKEN)

Next send the request:

F.Send()

Then assert and inspect the response:

F.ExpectStatus(200).
    ExpectJson("nested.path.to.value", "sometext").
    ExpectJson("nested.path.to.object", golangObject).
    ExpectJson("nested.array.7.id", 23).
    ExpectJsonLength("nested.array", 8).
    AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {
		val, _ := json.Get("proxy").String()
		frisby.Global.SetProxy(val)
	})

Finally, print out a report of the tests

frisby.Global.PrintReport()

Check any error(s), however the global report prints any that occured as well

err := F.Error()

errs := F.Errors()
for _,e := range errs {
	fmt.Println("Error: ", e)
}

HTTP Method functions

Your basic HTTP verbs:

  • Get(url string)
  • Post(url string)
  • Put(url string)
  • Patch(url string)
  • Delete(url string)
  • Head(url string)
  • Options(url string)

Pre-flight functions

Functions called before Send()

You can also set theses on the frisby.Global object for persisting state over multiple requests.

( Most of these come from github.com/mozillazg/request)

  • BasicAuth(username,password string)
  • Proxy(url string)
  • SetHeader(key,value string)
  • SetHeaders(map[string]string)
  • SetCookies(key,value string)
  • SetCookiess(map[string]string)
  • SetDate(key,value string)
  • SetDates(map[string]string)
  • SetParam(key,value string)
  • SetParams(map[string]string)
  • SetJson(interface{})
  • SetFile(filename string)

Post-flight functions

Functions called after Send()

  • ExpectStatus(code int)
  • ExpectHeader(key, value string)
  • ExpectContent(content string)
  • ExpectJson(path string, value interface{})
  • ExpectJsonLength(path string, length int)
  • ExpectJsonType(path string, value_type reflect.Kind)
  • AfterContent( func(Frisby,[]byte,error) )
  • AfterText( func(Frisby,string,error) )
  • AfterJson( func(Frisby,simplejson.Json,error) )
  • PauseTest(t time.Duration)
  • PrintBody()
  • PrintReport()
  • PrintGoTestReport()

More examples

You can find a longer example here

package main

import (
	"fmt"
	"reflect"

	"github.com/bitly/go-simplejson"
	"github.com/verdverm/frisby"
)

func main() {
	fmt.Println("Frisby!\n")

	frisby.Create("Test GET Go homepage").
		Get("http://golang.org").
		Send().
		ExpectStatus(200).
		ExpectContent("The Go Programming Language")

	frisby.Create("Test GET Go homepage (which fails)").
		Get("http://golang.org").
		Send().
		ExpectStatus(400).
		ExpectContent("A string which won't be found")

	frisby.Create("Test POST").
		Post("http://httpbin.org/post").
		SetData("test_key", "test_value").
		Send().
		ExpectStatus(200)

	frisby.Create("Test ExpectJsonType").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		ExpectJsonType("url", reflect.String)

	frisby.Create("Test ExpectJson").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		ExpectJson("url", "http://httpbin.org/post").
		ExpectJson("headers.Accept", "*/*")

	frisby.Create("Test ExpectJsonLength (which fails)").
		Post("http://httpbin.org/post").
		SetJson([]string{"item1", "item2", "item3"}).
		Send().
		ExpectStatus(200).
		ExpectJsonLength("json", 4)

	frisby.Create("Test AfterJson").
		Post("http://httpbin.org/post").
		Send().
		ExpectStatus(200).
		AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {
		val, _ := json.Get("url").String()
		frisby.Global.SetProxy(val)
	})

	frisby.Global.PrintReport()
}

Sample Output

Frisby!

.......
For 7 requests made
  FAILED  [3/13]
      [Test ExpectJsonLength]
        -  Expect length to be 4, but got 3
      [Test GET Go homepage (which fails)]
        -  Expected Status 400, but got 200: "200 OK"
        -  Expected Body to contain "A string which won't be found", but it was missing

catch!

More Repositories

1

self-driving-desktop

Desktop Automation Framework. Drive your mouse and keyboard with an easy to use language.
Python
576
star
2

hof

Framework that joins data models, schemas, code generation, and a task engine. Language and technology agnostic.
Go
499
star
3

cuetorials.com

Learn you some CUE for a great good!
CUE
114
star
4

cuetils

CLI and library for diff, patch, and ETL operations on CUE, JSON, and Yaml
Go
78
star
5

jumpfiles

get more done with fewer keystrokes
CUE
57
star
6

cuelm

Experiments with CUE on the quest to reimagine devops-ops.
CUE
34
star
7

hofmod-cli

Hofstadter generator for Golang CLIs
Go
25
star
8

cue-examples

Random examples demonstrating cuelang
20
star
9

harmony

Easily test downstream projects before releasing new code
CUE
14
star
10

harmony-cue

Harmony setup for testing CUE based projects
CUE
12
star
11

ghacue

GitHub Actions schema in CUE
CUE
10
star
12

c8s

Cuelang powered Kubernetes package manager
Go
8
star
13

hofmod-server

A hof generator for Golang servers
Go
7
star
14

mvs

A flexible Minimum Version Selection tool and library based on Go mods (MERGED into HOF, please see that project, all commands are the same)
Go
6
star
15

structural

Moved into hof, see this link ->
Go
4
star
16

flow-examples

Examples for hof/flow CUE powered DAG engine
CUE
4
star
17

cinful

Detect if your code is running in CI
Go
3
star
18

hofmod-struct

DSL for generating structs in various languages
Go
3
star
19

_awesome

Awesome List for and by Hofstadter
3
star
20

supacode

Hof generator for a full-stack app, built on NextJS
CUE
2
star
21

demos

demos of the hof cli
Go
2
star
22

data-utils

Common utilities for data (json,yaml,xml,toml) handling (io,type-inference,merge,patch,diff)
Go
2
star
23

homebrew-tap

Homebrew Tap for Hofstadter installables
Ruby
1
star
24

connector-js

JavaScript implementation of the 'connectors' concept. Dynamically merge, filter, and connect your project modules at build, init, or runtime.
JavaScript
1
star
25

kubeplex-server

Backend Go server for Kubeplex
Go
1
star
26

_mrtk

Docs, Tutorials, and Code Samples for the Mixed Reality Toolkit
1
star
27

hofmod-x

Experimental, reusable schemas, datamodels, generators, and flows
1
star
28

_saas

An open source toolset for SaaS operations.
Makefile
1
star
29

hofmod-cuefig

Application configuration using Cue
Go
1
star
30

flows

A collection of reusable and example `hof/flows` by and for the community
1
star
31

hof-starter-app

Starter application for Hofstadter Studios
TypeScript
1
star
32

cue.vim

Vim syntax plugin for Cuelang
Vim Script
1
star
33

old-hof

Replacement coming soon, stay tuned!
Go
1
star
34

hof-docs

Moved to the hof repo
CUE
1
star