httpunit: github.com/StackExchange/httpunit Index | Files

package httpunit

import "github.com/StackExchange/httpunit"

Package httpunit tests compliance of net services.

Index

Package Files

httpunit.go

Variables

var Timeout = time.Second * 10

Timeout is the connection timeout.

func ExtractHiera Uses

func ExtractHiera(fname string) ([]*TestPlan, error)

ExtractHiera returns listener members from a hiera sets.json file. For example, the following file would create three entries for the given IPs and ports. Other items present in the file are ignored.

{
  "iptables::sets::sets": {
    "listeners": {
      "members": {
        "10.0.1.2,tcp:80": {
          "comment": "first load balancer"
        },
        "10.0.3.4,tcp:80": {
          "comment": "second load balancer"
        },
        "10.0.7.8,tcp:25": {
          "comment": "mail servers"
        }
      }
    }
  }
}

type IPMap Uses

type IPMap map[string][]string

IPMap is a map of regular expressions to replacements.

func (IPMap) Expand Uses

func (i IPMap) Expand(s string) ([]string, error)

Expand expands s into IP addresses. A successful return will consist of valid IP addresses or "*". The following process is repeated until there are no changes. If an address is a valid IP address or "*", no further changes to it are done. If it contains the form "(x+y)", x and y are added and replaced. Otherwise a regular expression search and replace is done for each key of i with its values.

type PlanResult Uses

type PlanResult struct {
    Plan   *TestPlan
    Case   *TestCase
    Result *TestResult
}

type Plans Uses

type Plans struct {
    Plans []*TestPlan `toml:"plan"`
    IPs   IPMap
}

func (*Plans) Test Uses

func (ps *Plans) Test(filter string, no10 bool, tagFilters []string, protoFilters []string) (<-chan *PlanResult, int, error)

Test performs tests. Filter optionally specifies an IP filter to use. no10 disallows 10.* addresses. It returns a channel where results will be sent when complete, and the total number of results to expect. The channel is closed once all results are completed.

type Results Uses

type Results []*PlanResult

type TestCase Uses

type TestCase struct {
    URL  *url.URL
    IP   net.IP
    Port string

    Plan *TestPlan
    // FromDNS is true if IP was determined with a DNS lookup.
    FromDNS bool
    // Error is populated if the TestPlan could not create a TestCase. In this case
    // the test is not run, and this error is passed directly to the TestResult.
    Error error

    ExpectCode  int
    ExpectText  string
    ExpectRegex *regexp.Regexp

    Timeout time.Duration
}

func (*TestCase) Test Uses

func (c *TestCase) Test() *TestResult

Test performs this test case.

type TestPlan Uses

type TestPlan struct {
    Label string
    URL   string
    IPs   []string
    Tags  []string

    Code    int
    Text    string
    Regex   string
    Timeout time.Duration
}

TestPlan describes a test and its permutations (IP addresses).

func (*TestPlan) Cases Uses

func (p *TestPlan) Cases(filter string, no10 bool, IPs IPMap, protoFilters []string) ([]*TestCase, error)

Cases computes the actual test cases from a test plan. filter and no10 are described in Plans.Test.

type TestResult Uses

type TestResult struct {
    Result error
    Resp   *http.Response

    Connected   bool
    GotCode     bool
    GotText     bool
    GotRegex    bool
    InvalidCert bool
    TimeTotal   time.Duration
}

Package httpunit imports 13 packages (graph) and is imported by 1 packages. Updated 2016-10-03. Refresh now. Tools for package owners.