Exemple #1
0
func TestExtractLinks(t *testing.T) {
	tests := []ExtractLinksData{
		{
			"test1",
			"<a href='foo.html' rel='foo'>Oink</a>",
			map[string]string{
				"foo": "foo.html",
			},
		},
		{
			"test2",
			"<a href='foo.html'>Oink</a>",
			map[string]string{},
		},
		{
			"test3",
			"<title>Foo bar</title><a href='#trash' rel='trash'><a href='oink'></close>",
			map[string]string{
				"trash": "#trash",
			},
		},
	}
	for _, test := range tests {
		links := extractLinks(strings.NewReader(test.html))
		if !reflect.DeepEqual(test.links, links) {
			spew.Fprintf(os.Stderr, "extractLinks test '%s' failed.\nExpected:\n%v\n\nGot:\n%v\n",
				test.name, test.links, links)
			t.Fatal()
		}
	}
}
Exemple #2
0
// Dumpf formats and displays the passed parameters with newlines and additional debug information such as complete types and all pointer addresses used to indirect to the final value.
// Delegates to spew.Fprintf, see http://godoc.org/github.com/davecgh/go-spew/spew#Dump
func (w *Watchpoint) Dumpf(format string, a ...interface{}) *Watchpoint {
	writer := new(bytes.Buffer)
	_, err := spew.Fprintf(writer, format, a...)
	if err != nil {
		return Printf("[hopwatch] error in spew.Fprintf:%v", err)
	}
	return w.printcontent(string(writer.Bytes()))
}
Exemple #3
0
func logInfo(trid int, sTime time.Time, msg string, params ...interface{}) {
	//timestamp spentTime peer x-real-ip method status 'request URI' message
	spew.Fprintf(os.Stderr, "Thread %d: %s %d %s\n",
		trid,
		sTime.Local().Format("2006-01-02-15-04-05.000"),
		int(time.Now().Sub(sTime).Seconds()*1000),
		spew.Sprintf(msg, params...),
	)
}
Exemple #4
0
func main() {
	cfg.Parse()
	spew.Fprintf(os.Stderr, "started: %#v\n", cfg)

	statsdInit(*cfg.statsd_host, *cfg.statsd_port, *cfg.statsd_prefix, *cfg.statsd_tags)

	getStat()

	for *cfg.interval > 0 {
		time.Sleep(time.Duration(*cfg.interval) * time.Second)
		getStat()
	}
}
Exemple #5
0
func TestUnmarshal(t *testing.T) {
	for i, tt := range unmarshalTests {
		out, err := Unmarshal(tt.in)
		if err != nil {
			t.Fatalf("%d. received error: %s", i, err)
		}

		b1 := &bytes.Buffer{}
		b2 := &bytes.Buffer{}

		spew.Fprintf(b1, "%#v", out)
		spew.Fprintf(b2, "%#v", tt.out)

		if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
			t.Fatalf("#%d: mismatch\nexpected: %s\ngot: %s", i, b2.String(), b1.String())
		}

		// Cannot deep equal because the data contains pointers which are
		// compared by their address.
		// if !reflect.DeepEqual(out, tt.out) {
		//   t.Fatalf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, out, tt.out)
		// }
	}
}
Exemple #6
0
func main() {
	cfg.Parse()
	spew.Fprintf(os.Stderr, "started: %#v\n", cfg)

	if *cfg.ssl {
		panic(fmt.Errorf("SSL not implemented yet"))
	}

	go slidingPassword.UpdateLoop(time.Duration(*cfg.authTTL/2*1000) * time.Millisecond)

	http.Handle(*cfg.baseuri, RootGetPost{http.StripPrefix(*cfg.baseuri, http.FileServer(http.Dir(*cfg.root)))})
	http.Handle(*cfg.baseuri+"logon", LogonHandler{})
	http.Handle(*cfg.baseuri+"retry", RetryHandler{})
	http.Handle(*cfg.baseuri+"websockify", NewWssHandler())

	panic(http.ListenAndServe(*cfg.listen, nil))
}
Exemple #7
0
func dns(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query().Get("q")
	// Note that the below is NOT safe from input attacks, but that's OK
	// because this is just for debugging.
	fmt.Fprintf(w, `<html><body>
<form action="/dns">
<input name="q" type="text" value="%v"></input>
<button type="submit">Lookup</button>
</form>
<br/><br/><pre>`, q)
	{
		res, err := net.LookupNS(q)
		spew.Fprintf(w, "LookupNS(%v):\nResult: %#v\nError: %v\n\n", q, res, err)
	}
	{
		res, err := net.LookupTXT(q)
		spew.Fprintf(w, "LookupTXT(%v):\nResult: %#v\nError: %v\n\n", q, res, err)
	}
	{
		cname, res, err := net.LookupSRV("", "", q)
		spew.Fprintf(w, `LookupSRV("", "", %v):
cname: %v
Result: %#v
Error: %v

`, q, cname, res, err)
	}
	{
		res, err := net.LookupHost(q)
		spew.Fprintf(w, "LookupHost(%v):\nResult: %#v\nError: %v\n\n", q, res, err)
	}
	{
		res, err := net.LookupIP(q)
		spew.Fprintf(w, "LookupIP(%v):\nResult: %#v\nError: %v\n\n", q, res, err)
	}
	{
		res, err := net.LookupMX(q)
		spew.Fprintf(w, "LookupMX(%v):\nResult: %#v\nError: %v\n\n", q, res, err)
	}
	fmt.Fprintf(w, `</pre>
</body>
</html>`)
}
Exemple #8
0
// DeepHashObject writes specified object to hash using the spew library
// which follows pointers and prints actual values of the nested objects
// ensuring the hash does not change when a pointer changes.
func DeepHashObject(hasher hash.Hash, objectToWrite interface{}) {
	spew.Fprintf(hasher, "%#v", objectToWrite)
}