ght

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2017 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GHT

GHT (GHT HTTP Tester) aims to make it easy to create automated HTTP test scripts.

Software License Travis Go Doc Go Report Card

Installation:

go get github.com/ramjac/ght/...

Using the tool

Running an excel file looks simply like this:

ght -excel testfile.xlsx

An example test file is provided in this repo. The test file works on local godoc and gotour servers. A flag -v will print verbose output.

The csv test format looks like this:

<url>,<headers as key1:value1&key2:value2>,<expected HTTP status code>,<expected content type>,<regex>,<bool should regex match>

Some examples run with godoc -http=:8080

ght -r 1 -t 1 -csv "http://localhost:8080/djjff,,404,,,,http://localhost:8080,,200,text/html; charset=utf-8,,,http://localhost:8080,,200,,(Download go),true"

Case insentive example

ght -v -r 1 -te 1 -to 1 -csv "http://localhost:8080,,200,,(?i)(download go),true"

A nice little reference for Regex as parsed by Golang https://regex-golang.appspot.com/assets/html/index.html

TODO

  • Remove time.Sleep from TryRequest
  • Allow for a JSON file input of whose schema is based on an array of the HTTPTest struct
  • Improve verbose output
    • The verbose output should summarize what failed. There is a summary, but this could be more helpful.
    • The HTTP request and response should pretty print
  • Fix a minor bug where spreadsheet rows that lack retries/time elapse/timeout fail to run
  • Add some kind of authentication flow
    • Allow for "Set-Cookie" in a response to set the Cookies of future requests
    • Use the "token: ..." in response to set the "Authorization: " header of future requests
    • Do these two scenarios cover enough? (not cover everything, just enough)
    • How does this fit into the current test runner?
      • Perhaps CSV tests should execute serially?
      • Perhaps serially per tab?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHTTPTest

func AddHTTPTest(t *HTTPTest, r *[]*HTTPTest)

AddHTTPTest appends an HTTPTest to the given slice.

Types

type HTTPTest

type HTTPTest struct {
	Request                      *http.Request
	ExpectedStatus               int
	ExpectedType                 string
	Regex                        *regexp.Regexp
	ExpectMatch                  bool
	Retries, TimeElapse, TimeOut int
}

HTTPTest is a request to be tested.

func ImportExcel

func ImportExcel(fileName, tabsToTest *string, logger *VerboseLogger, retries, timeElapse, timeOut int) (r []*HTTPTest)

ImportExcel takes an excel of the correct format and returns a slice of HTTPTest.

func ParseCSV

func ParseCSV(rawCSV *string, logger *VerboseLogger, retries, timeElapse, timeOut int) (r []*HTTPTest)

ParseCSV takes a csv of the correct format and returns a slice of HTTPTest.

func (*HTTPTest) Equals

func (h *HTTPTest) Equals(c *HTTPTest) bool

Equals checks to see if two HTTPTests have the same field values.

func (*HTTPTest) String

func (h *HTTPTest) String() string

Some basic pretty printing. This could use improvement.

func (*HTTPTest) TryRequest

func (h *HTTPTest) TryRequest(ctx context.Context, cancel func(), logger *VerboseLogger, wg *sync.WaitGroup) bool

TryRequest will attempt an HTTP request as many times as specifie and return true if it reaches a successful response.

type VerboseLogger

type VerboseLogger struct{}

VerboseLogger only logs when the verbose variable is true.

func (*VerboseLogger) IsVerbose

func (l *VerboseLogger) IsVerbose() bool

IsVerbose specifies if the logger should log human friendly output. This is nice for a program that has either human friendly verbose output or terse machine friendly return codes.

func (*VerboseLogger) New

func (l *VerboseLogger) New(v *bool)

New creates a new VerboseLogger using the referenced bool to set verbosity.

func (*VerboseLogger) Printf

func (l *VerboseLogger) Printf(s string, v ...interface{})

Printf prints if verbose is true.

func (*VerboseLogger) Println

func (l *VerboseLogger) Println(v ...interface{})

Println prints a line if verbose is true.

Directories

Path Synopsis
cmd
ght command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址