1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
// Copyright 2013-2015 Apcera Inc. All rights reserved.
// +build clienttest
package test
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"
"testing"
)
func verifyInquireContextResult(t *testing.T, result string, regexps []string) {
rr := strings.Split(result, " ")
if len(rr) != len(regexps) {
t.Fatalf("got %v fragments, expected %v (%s)", len(rr), len(regexps), result)
}
for i, r := range rr {
rx := regexp.MustCompile(regexps[i])
if !rx.MatchString(r) {
t.Errorf("%s does not match %s", r, regexps[i])
}
}
}
func TestClientInquireContext(t *testing.T) {
ctx, r := initClientContext(t, "GET", "/inquire_context/", nil)
defer ctx.Release()
srcName, targetName, lifetimeRec, mechType, ctxFlags,
locallyInitiated, open, err := ctx.InquireContext()
if err != nil {
t.Fatal(err)
}
defer srcName.Release()
defer targetName.Release()
verifyInquireContextResult(t,
fmt.Sprintf("%q %q %v %q %x %v %v",
srcName, targetName, lifetimeRec, mechType.DebugString(), ctxFlags,
locallyInitiated, open),
[]string{
`"[a-zA-Z_-]+@[[:graph:]]+"`,
`"HTTP/[[:graph:]]+@[[:graph:]]+"`,
`[0-9a-z]+`,
`[A-Z]+`,
"1b0",
"true",
"true",
})
resp, err := http.DefaultClient.Do(r)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("Expected status 200, got %v", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
verifyInquireContextResult(t, string(body),
[]string{
`"[a-zA-Z_-]+@[[:graph:]]+"`,
`"HTTP/[[:graph:]]+@[[:graph:]]+"`,
`[0-9a-z]+`,
`[A-Z]+`,
"130",
"false",
"true",
})
}
|