Use Go 1.5 vendoring instead of Godeps
Change made by: - running "gvt fetch" on each of the packages mentioned in Godeps/Godeps.json - `rm -rf Godeps` - tweaking the build scripts to not mention Godeps - tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly (to avoid testing vendor) - tweaking the build scripts to not juggle GOPATH for Godeps and instead set GO15VENDOREXPERIMENT. This also results in some updated packages at the same time I bet. Building with Go 1.3 and 1.4 still *works* but won't use our vendored dependencies - the user needs to have the actual packages in their GOPATH then, which they'll get with a normal "go get". Building with Go 1.6+ will get our vendored dependencies by default even when not using our build script, which is nice. By doing this we gain some freedom in that we can pick and choose manually what to include in vendor, as it's not based on just dependency analysis of our own code. This is also a risk as we might pick up dependencies we are unaware of, as the build may work locally with those packages present in GOPATH. On the other hand the build server will detect this as it has no packages in it's GOPATH beyond what is included in the repo. Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
This commit is contained in:
19
vendor/github.com/stathat/go/LICENSE
generated
vendored
Normal file
19
vendor/github.com/stathat/go/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (C) 2012 Numerotron Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
67
vendor/github.com/stathat/go/README.md
generated
vendored
Normal file
67
vendor/github.com/stathat/go/README.md
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
stathat
|
||||
=======
|
||||
|
||||
This is a Go package for posting stats to your StatHat account.
|
||||
|
||||
For more information about StatHat, visit [www.stathat.com](http://www.stathat.com).
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Use `go get`:
|
||||
|
||||
go get github.com/stathat/go
|
||||
|
||||
That's it.
|
||||
|
||||
Import it like this:
|
||||
|
||||
import (
|
||||
"github.com/stathat/go"
|
||||
)
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
The easiest way to use the package is with the EZ API functions. You can add stats
|
||||
directly in your code by just adding a call with a new stat name. Once StatHat
|
||||
receives the call, a new stat will be created for you.
|
||||
|
||||
To post a count of 1 to a stat:
|
||||
|
||||
stathat.PostEZCountOne("messages sent - female to male", "something@stathat.com")
|
||||
|
||||
To specify the count:
|
||||
|
||||
stathat.PostEZCount("messages sent - male to male", "something@stathat.com", 37)
|
||||
|
||||
To post a value:
|
||||
|
||||
stathat.PostEZValue("ws0 load average", "something@stathat.com", 0.372)
|
||||
|
||||
There are also functions for the classic API. The drawback to the classic API is
|
||||
that you need to create the stats using the web interface and copy the keys it
|
||||
gives you into your code.
|
||||
|
||||
To post a count of 1 to a stat using the classic API:
|
||||
|
||||
stathat.PostCountOne("statkey", "userkey")
|
||||
|
||||
To specify the count:
|
||||
|
||||
stathat.PostCount("statkey", "userkey", 37)
|
||||
|
||||
To post a value:
|
||||
|
||||
stathat.PostValue("statkey", "userkey", 0.372)
|
||||
|
||||
Contact us
|
||||
----------
|
||||
|
||||
We'd love to hear from you if you are using this in your projects! Please drop us a
|
||||
line: [@stat_hat](http://twitter.com/stat_hat) or [contact us here](http://www.stathat.com/docs/contact).
|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
Written by Patrick Crosby at [StatHat](http://www.stathat.com). Twitter: [@stat_hat](http://twitter.com/stat_hat)
|
||||
29
vendor/github.com/stathat/go/example_test.go
generated
vendored
Normal file
29
vendor/github.com/stathat/go/example_test.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2012 Numerotron Inc.
|
||||
// Use of this source code is governed by an MIT-style license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package stathat_test
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
stathat "github.com/stathat/go"
|
||||
)
|
||||
|
||||
func ExamplePostEZCountOne() {
|
||||
log.Printf("starting example")
|
||||
stathat.Verbose = true
|
||||
err := stathat.PostEZCountOne("go example test run", "nobody@stathat.com")
|
||||
if err != nil {
|
||||
log.Printf("error posting ez count one: %v", err)
|
||||
return
|
||||
}
|
||||
// If using this with a valid account, this could be helpful in a short script:
|
||||
/*
|
||||
ok := stathat.WaitUntilFinished(5 * time.Second)
|
||||
if ok {
|
||||
fmt.Println("ok")
|
||||
}
|
||||
*/
|
||||
// Output:
|
||||
}
|
||||
431
vendor/github.com/stathat/go/stathat.go
generated
vendored
Normal file
431
vendor/github.com/stathat/go/stathat.go
generated
vendored
Normal file
@@ -0,0 +1,431 @@
|
||||
// Copyright (C) 2012 Numerotron Inc.
|
||||
// Use of this source code is governed by an MIT-style license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
// Copyright 2012 Numerotron Inc.
|
||||
// Use of this source code is governed by an MIT-style license
|
||||
// that can be found in the LICENSE file.
|
||||
//
|
||||
// Developed at www.stathat.com by Patrick Crosby
|
||||
// Contact us on twitter with any questions: twitter.com/stat_hat
|
||||
|
||||
// The stathat package makes it easy to post any values to your StatHat
|
||||
// account.
|
||||
package stathat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const hostname = "api.stathat.com"
|
||||
|
||||
type statKind int
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
kcounter statKind = iota
|
||||
kvalue
|
||||
)
|
||||
|
||||
func (sk statKind) classicPath() string {
|
||||
switch sk {
|
||||
case kcounter:
|
||||
return "/c"
|
||||
case kvalue:
|
||||
return "/v"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type apiKind int
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
classic apiKind = iota
|
||||
ez
|
||||
)
|
||||
|
||||
func (ak apiKind) path(sk statKind) string {
|
||||
switch ak {
|
||||
case ez:
|
||||
return "/ez"
|
||||
case classic:
|
||||
return sk.classicPath()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type statReport struct {
|
||||
StatKey string
|
||||
UserKey string
|
||||
Value float64
|
||||
Timestamp int64
|
||||
statType statKind
|
||||
apiType apiKind
|
||||
}
|
||||
|
||||
// Reporter is a StatHat client that can report stat values/counts to the servers.
|
||||
type Reporter struct {
|
||||
reports chan *statReport
|
||||
done chan bool
|
||||
client *http.Client
|
||||
wg *sync.WaitGroup
|
||||
}
|
||||
|
||||
// NewReporter returns a new Reporter. You must specify the channel bufferSize and the
|
||||
// goroutine poolSize. You can pass in nil for the transport and it will create an
|
||||
// http transport with MaxIdleConnsPerHost set to the goroutine poolSize. Note if you
|
||||
// pass in your own transport, it's a good idea to have its MaxIdleConnsPerHost be set
|
||||
// to at least the poolSize to allow for effective connection reuse.
|
||||
func NewReporter(bufferSize, poolSize int, transport http.RoundTripper) *Reporter {
|
||||
r := new(Reporter)
|
||||
if transport == nil {
|
||||
transport = &http.Transport{
|
||||
// Allow for an idle connection per goroutine.
|
||||
MaxIdleConnsPerHost: poolSize,
|
||||
}
|
||||
}
|
||||
r.client = &http.Client{Transport: transport}
|
||||
r.reports = make(chan *statReport, bufferSize)
|
||||
r.done = make(chan bool)
|
||||
r.wg = new(sync.WaitGroup)
|
||||
for i := 0; i < poolSize; i++ {
|
||||
r.wg.Add(1)
|
||||
go r.processReports()
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// DefaultReporter is the default instance of *Reporter.
|
||||
var DefaultReporter = NewReporter(100000, 10, nil)
|
||||
|
||||
var testingEnv = false
|
||||
|
||||
type testPost struct {
|
||||
url string
|
||||
values url.Values
|
||||
}
|
||||
|
||||
var testPostChannel chan *testPost
|
||||
|
||||
// The Verbose flag determines if the package should write verbose output to stdout.
|
||||
var Verbose = false
|
||||
|
||||
func setTesting() {
|
||||
testingEnv = true
|
||||
testPostChannel = make(chan *testPost)
|
||||
}
|
||||
|
||||
func newEZStatCount(statName, ezkey string, count int) *statReport {
|
||||
return &statReport{StatKey: statName,
|
||||
UserKey: ezkey,
|
||||
Value: float64(count),
|
||||
statType: kcounter,
|
||||
apiType: ez}
|
||||
}
|
||||
|
||||
func newEZStatValue(statName, ezkey string, value float64) *statReport {
|
||||
return &statReport{StatKey: statName,
|
||||
UserKey: ezkey,
|
||||
Value: value,
|
||||
statType: kvalue,
|
||||
apiType: ez}
|
||||
}
|
||||
|
||||
func newClassicStatCount(statKey, userKey string, count int) *statReport {
|
||||
return &statReport{StatKey: statKey,
|
||||
UserKey: userKey,
|
||||
Value: float64(count),
|
||||
statType: kcounter,
|
||||
apiType: classic}
|
||||
}
|
||||
|
||||
func newClassicStatValue(statKey, userKey string, value float64) *statReport {
|
||||
return &statReport{StatKey: statKey,
|
||||
UserKey: userKey,
|
||||
Value: value,
|
||||
statType: kvalue,
|
||||
apiType: classic}
|
||||
}
|
||||
|
||||
func (sr *statReport) values() url.Values {
|
||||
switch sr.apiType {
|
||||
case ez:
|
||||
return sr.ezValues()
|
||||
case classic:
|
||||
return sr.classicValues()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sr *statReport) ezValues() url.Values {
|
||||
switch sr.statType {
|
||||
case kcounter:
|
||||
return sr.ezCounterValues()
|
||||
case kvalue:
|
||||
return sr.ezValueValues()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sr *statReport) classicValues() url.Values {
|
||||
switch sr.statType {
|
||||
case kcounter:
|
||||
return sr.classicCounterValues()
|
||||
case kvalue:
|
||||
return sr.classicValueValues()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sr *statReport) ezCommonValues() url.Values {
|
||||
result := make(url.Values)
|
||||
result.Set("stat", sr.StatKey)
|
||||
result.Set("ezkey", sr.UserKey)
|
||||
if sr.Timestamp > 0 {
|
||||
result.Set("t", sr.timeString())
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (sr *statReport) classicCommonValues() url.Values {
|
||||
result := make(url.Values)
|
||||
result.Set("key", sr.StatKey)
|
||||
result.Set("ukey", sr.UserKey)
|
||||
if sr.Timestamp > 0 {
|
||||
result.Set("t", sr.timeString())
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (sr *statReport) ezCounterValues() url.Values {
|
||||
result := sr.ezCommonValues()
|
||||
result.Set("count", sr.valueString())
|
||||
return result
|
||||
}
|
||||
|
||||
func (sr *statReport) ezValueValues() url.Values {
|
||||
result := sr.ezCommonValues()
|
||||
result.Set("value", sr.valueString())
|
||||
return result
|
||||
}
|
||||
|
||||
func (sr *statReport) classicCounterValues() url.Values {
|
||||
result := sr.classicCommonValues()
|
||||
result.Set("count", sr.valueString())
|
||||
return result
|
||||
}
|
||||
|
||||
func (sr *statReport) classicValueValues() url.Values {
|
||||
result := sr.classicCommonValues()
|
||||
result.Set("value", sr.valueString())
|
||||
return result
|
||||
}
|
||||
|
||||
func (sr *statReport) valueString() string {
|
||||
return strconv.FormatFloat(sr.Value, 'g', -1, 64)
|
||||
}
|
||||
|
||||
func (sr *statReport) timeString() string {
|
||||
return strconv.FormatInt(sr.Timestamp, 10)
|
||||
}
|
||||
|
||||
func (sr *statReport) path() string {
|
||||
return sr.apiType.path(sr.statType)
|
||||
}
|
||||
|
||||
func (sr *statReport) url() string {
|
||||
return fmt.Sprintf("https://%s%s", hostname, sr.path())
|
||||
}
|
||||
|
||||
// Using the classic API, posts a count to a stat using DefaultReporter.
|
||||
func PostCount(statKey, userKey string, count int) error {
|
||||
return DefaultReporter.PostCount(statKey, userKey, count)
|
||||
}
|
||||
|
||||
// Using the classic API, posts a count to a stat using DefaultReporter at a specific
|
||||
// time.
|
||||
func PostCountTime(statKey, userKey string, count int, timestamp int64) error {
|
||||
return DefaultReporter.PostCountTime(statKey, userKey, count, timestamp)
|
||||
}
|
||||
|
||||
// Using the classic API, posts a count of 1 to a stat using DefaultReporter.
|
||||
func PostCountOne(statKey, userKey string) error {
|
||||
return DefaultReporter.PostCountOne(statKey, userKey)
|
||||
}
|
||||
|
||||
// Using the classic API, posts a value to a stat using DefaultReporter.
|
||||
func PostValue(statKey, userKey string, value float64) error {
|
||||
return DefaultReporter.PostValue(statKey, userKey, value)
|
||||
}
|
||||
|
||||
// Using the classic API, posts a value to a stat at a specific time using DefaultReporter.
|
||||
func PostValueTime(statKey, userKey string, value float64, timestamp int64) error {
|
||||
return DefaultReporter.PostValueTime(statKey, userKey, value, timestamp)
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a count of 1 to a stat using DefaultReporter.
|
||||
func PostEZCountOne(statName, ezkey string) error {
|
||||
return DefaultReporter.PostEZCountOne(statName, ezkey)
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a count to a stat using DefaultReporter.
|
||||
func PostEZCount(statName, ezkey string, count int) error {
|
||||
return DefaultReporter.PostEZCount(statName, ezkey, count)
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a count to a stat at a specific time using DefaultReporter.
|
||||
func PostEZCountTime(statName, ezkey string, count int, timestamp int64) error {
|
||||
return DefaultReporter.PostEZCountTime(statName, ezkey, count, timestamp)
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a value to a stat using DefaultReporter.
|
||||
func PostEZValue(statName, ezkey string, value float64) error {
|
||||
return DefaultReporter.PostEZValue(statName, ezkey, value)
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a value to a stat at a specific time using DefaultReporter.
|
||||
func PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error {
|
||||
return DefaultReporter.PostEZValueTime(statName, ezkey, value, timestamp)
|
||||
}
|
||||
|
||||
// Wait for all stats to be sent, or until timeout. Useful for simple command-
|
||||
// line apps to defer a call to this in main()
|
||||
func WaitUntilFinished(timeout time.Duration) bool {
|
||||
return DefaultReporter.WaitUntilFinished(timeout)
|
||||
}
|
||||
|
||||
// Using the classic API, posts a count to a stat.
|
||||
func (r *Reporter) PostCount(statKey, userKey string, count int) error {
|
||||
r.add(newClassicStatCount(statKey, userKey, count))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the classic API, posts a count to a stat at a specific time.
|
||||
func (r *Reporter) PostCountTime(statKey, userKey string, count int, timestamp int64) error {
|
||||
x := newClassicStatCount(statKey, userKey, count)
|
||||
x.Timestamp = timestamp
|
||||
r.add(x)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the classic API, posts a count of 1 to a stat.
|
||||
func (r *Reporter) PostCountOne(statKey, userKey string) error {
|
||||
return r.PostCount(statKey, userKey, 1)
|
||||
}
|
||||
|
||||
// Using the classic API, posts a value to a stat.
|
||||
func (r *Reporter) PostValue(statKey, userKey string, value float64) error {
|
||||
r.add(newClassicStatValue(statKey, userKey, value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the classic API, posts a value to a stat at a specific time.
|
||||
func (r *Reporter) PostValueTime(statKey, userKey string, value float64, timestamp int64) error {
|
||||
x := newClassicStatValue(statKey, userKey, value)
|
||||
x.Timestamp = timestamp
|
||||
r.add(x)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a count of 1 to a stat.
|
||||
func (r *Reporter) PostEZCountOne(statName, ezkey string) error {
|
||||
return r.PostEZCount(statName, ezkey, 1)
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a count to a stat.
|
||||
func (r *Reporter) PostEZCount(statName, ezkey string, count int) error {
|
||||
r.add(newEZStatCount(statName, ezkey, count))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a count to a stat at a specific time.
|
||||
func (r *Reporter) PostEZCountTime(statName, ezkey string, count int, timestamp int64) error {
|
||||
x := newEZStatCount(statName, ezkey, count)
|
||||
x.Timestamp = timestamp
|
||||
r.add(x)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a value to a stat.
|
||||
func (r *Reporter) PostEZValue(statName, ezkey string, value float64) error {
|
||||
r.add(newEZStatValue(statName, ezkey, value))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Using the EZ API, posts a value to a stat at a specific time.
|
||||
func (r *Reporter) PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error {
|
||||
x := newEZStatValue(statName, ezkey, value)
|
||||
x.Timestamp = timestamp
|
||||
r.add(x)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Reporter) processReports() {
|
||||
for sr := range r.reports {
|
||||
if Verbose {
|
||||
log.Printf("posting stat to stathat: %s, %v", sr.url(), sr.values())
|
||||
}
|
||||
|
||||
if testingEnv {
|
||||
if Verbose {
|
||||
log.Printf("in test mode, putting stat on testPostChannel")
|
||||
}
|
||||
testPostChannel <- &testPost{sr.url(), sr.values()}
|
||||
continue
|
||||
}
|
||||
|
||||
resp, err := r.client.PostForm(sr.url(), sr.values())
|
||||
if err != nil {
|
||||
log.Printf("error posting stat to stathat: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if Verbose {
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
log.Printf("stathat post result: %s", body)
|
||||
} else {
|
||||
// Read the body even if we don't intend to use it. Otherwise golang won't pool the connection.
|
||||
// See also: http://stackoverflow.com/questions/17948827/reusing-http-connections-in-golang/17953506#17953506
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
}
|
||||
|
||||
resp.Body.Close()
|
||||
}
|
||||
r.wg.Done()
|
||||
}
|
||||
|
||||
func (r *Reporter) add(rep *statReport) {
|
||||
select {
|
||||
case r.reports <- rep:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reporter) finish() {
|
||||
close(r.reports)
|
||||
r.wg.Wait()
|
||||
r.done <- true
|
||||
}
|
||||
|
||||
// Wait for all stats to be sent, or until timeout. Useful for simple command-
|
||||
// line apps to defer a call to this in main()
|
||||
func (r *Reporter) WaitUntilFinished(timeout time.Duration) bool {
|
||||
go r.finish()
|
||||
select {
|
||||
case <-r.done:
|
||||
return true
|
||||
case <-time.After(timeout):
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
319
vendor/github.com/stathat/go/stathat_test.go
generated
vendored
Normal file
319
vendor/github.com/stathat/go/stathat_test.go
generated
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
// Copyright (C) 2012 Numerotron Inc.
|
||||
// Use of this source code is governed by an MIT-style license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package stathat
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewEZStatCount(t *testing.T) {
|
||||
setTesting()
|
||||
x := newEZStatCount("abc", "pc@pc.com", 1)
|
||||
if x == nil {
|
||||
t.Fatalf("expected a StatReport object")
|
||||
}
|
||||
if x.statType != kcounter {
|
||||
t.Errorf("expected counter")
|
||||
}
|
||||
if x.apiType != ez {
|
||||
t.Errorf("expected EZ api")
|
||||
}
|
||||
if x.StatKey != "abc" {
|
||||
t.Errorf("expected abc")
|
||||
}
|
||||
if x.UserKey != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if x.Value != 1.0 {
|
||||
t.Errorf("expected 1.0")
|
||||
}
|
||||
if x.Timestamp != 0 {
|
||||
t.Errorf("expected 0")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewEZStatValue(t *testing.T) {
|
||||
setTesting()
|
||||
x := newEZStatValue("abc", "pc@pc.com", 3.14159)
|
||||
if x == nil {
|
||||
t.Fatalf("expected a StatReport object")
|
||||
}
|
||||
if x.statType != kvalue {
|
||||
t.Errorf("expected value")
|
||||
}
|
||||
if x.apiType != ez {
|
||||
t.Errorf("expected EZ api")
|
||||
}
|
||||
if x.StatKey != "abc" {
|
||||
t.Errorf("expected abc")
|
||||
}
|
||||
if x.UserKey != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if x.Value != 3.14159 {
|
||||
t.Errorf("expected 3.14159")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewClassicStatCount(t *testing.T) {
|
||||
setTesting()
|
||||
x := newClassicStatCount("statkey", "userkey", 1)
|
||||
if x == nil {
|
||||
t.Fatalf("expected a StatReport object")
|
||||
}
|
||||
if x.statType != kcounter {
|
||||
t.Errorf("expected counter")
|
||||
}
|
||||
if x.apiType != classic {
|
||||
t.Errorf("expected CLASSIC api")
|
||||
}
|
||||
if x.StatKey != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if x.UserKey != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if x.Value != 1.0 {
|
||||
t.Errorf("expected 1.0")
|
||||
}
|
||||
if x.Timestamp != 0 {
|
||||
t.Errorf("expected 0")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewClassicStatValue(t *testing.T) {
|
||||
setTesting()
|
||||
x := newClassicStatValue("statkey", "userkey", 2.28)
|
||||
if x == nil {
|
||||
t.Fatalf("expected a StatReport object")
|
||||
}
|
||||
if x.statType != kvalue {
|
||||
t.Errorf("expected value")
|
||||
}
|
||||
if x.apiType != classic {
|
||||
t.Errorf("expected CLASSIC api")
|
||||
}
|
||||
if x.StatKey != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if x.UserKey != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if x.Value != 2.28 {
|
||||
t.Errorf("expected 2.28")
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLValues(t *testing.T) {
|
||||
setTesting()
|
||||
x := newEZStatCount("abc", "pc@pc.com", 1)
|
||||
v := x.values()
|
||||
if v == nil {
|
||||
t.Fatalf("expected url values")
|
||||
}
|
||||
if v.Get("stat") != "abc" {
|
||||
t.Errorf("expected abc")
|
||||
}
|
||||
if v.Get("ezkey") != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if v.Get("count") != "1" {
|
||||
t.Errorf("expected count of 1")
|
||||
}
|
||||
|
||||
y := newEZStatValue("abc", "pc@pc.com", 3.14159)
|
||||
v = y.values()
|
||||
if v == nil {
|
||||
t.Fatalf("expected url values")
|
||||
}
|
||||
if v.Get("stat") != "abc" {
|
||||
t.Errorf("expected abc")
|
||||
}
|
||||
if v.Get("ezkey") != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if v.Get("value") != "3.14159" {
|
||||
t.Errorf("expected value of 3.14159")
|
||||
}
|
||||
|
||||
a := newClassicStatCount("statkey", "userkey", 1)
|
||||
v = a.values()
|
||||
if v == nil {
|
||||
t.Fatalf("expected url values")
|
||||
}
|
||||
if v.Get("key") != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if v.Get("ukey") != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if v.Get("count") != "1" {
|
||||
t.Errorf("expected count of 1")
|
||||
}
|
||||
|
||||
b := newClassicStatValue("statkey", "userkey", 2.28)
|
||||
v = b.values()
|
||||
if v == nil {
|
||||
t.Fatalf("expected url values")
|
||||
}
|
||||
if v.Get("key") != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if v.Get("ukey") != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if v.Get("value") != "2.28" {
|
||||
t.Errorf("expected value of 2.28")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaths(t *testing.T) {
|
||||
if ez.path(kcounter) != "/ez" {
|
||||
t.Errorf("expected /ez")
|
||||
}
|
||||
if ez.path(kvalue) != "/ez" {
|
||||
t.Errorf("expected /ez")
|
||||
}
|
||||
if classic.path(kcounter) != "/c" {
|
||||
t.Errorf("expected /c")
|
||||
}
|
||||
if classic.path(kvalue) != "/v" {
|
||||
t.Errorf("expected /v")
|
||||
}
|
||||
|
||||
x := newEZStatCount("abc", "pc@pc.com", 1)
|
||||
if x.path() != "/ez" {
|
||||
t.Errorf("expected /ez")
|
||||
}
|
||||
y := newEZStatValue("abc", "pc@pc.com", 3.14159)
|
||||
if y.path() != "/ez" {
|
||||
t.Errorf("expected /ez")
|
||||
}
|
||||
a := newClassicStatCount("statkey", "userkey", 1)
|
||||
if a.path() != "/c" {
|
||||
t.Errorf("expected /c")
|
||||
}
|
||||
b := newClassicStatValue("statkey", "userkey", 2.28)
|
||||
if b.path() != "/v" {
|
||||
t.Errorf("expected /v")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPosts(t *testing.T) {
|
||||
setTesting()
|
||||
PostCountOne("statkey", "userkey")
|
||||
p := <-testPostChannel
|
||||
if p.url != "https://api.stathat.com/c" {
|
||||
t.Errorf("expected classic count url")
|
||||
}
|
||||
if p.values.Get("key") != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if p.values.Get("ukey") != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if p.values.Get("count") != "1" {
|
||||
t.Errorf("expected count of 1")
|
||||
}
|
||||
|
||||
PostCount("statkey", "userkey", 13)
|
||||
p = <-testPostChannel
|
||||
if p.url != "https://api.stathat.com/c" {
|
||||
t.Errorf("expected classic count url")
|
||||
}
|
||||
if p.values.Get("key") != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if p.values.Get("ukey") != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if p.values.Get("count") != "13" {
|
||||
t.Errorf("expected count of 13")
|
||||
}
|
||||
|
||||
PostValue("statkey", "userkey", 9.312)
|
||||
p = <-testPostChannel
|
||||
if p.url != "https://api.stathat.com/v" {
|
||||
t.Errorf("expected classic value url")
|
||||
}
|
||||
if p.values.Get("key") != "statkey" {
|
||||
t.Errorf("expected statkey")
|
||||
}
|
||||
if p.values.Get("ukey") != "userkey" {
|
||||
t.Errorf("expected userkey")
|
||||
}
|
||||
if p.values.Get("value") != "9.312" {
|
||||
t.Errorf("expected value of 9.312")
|
||||
}
|
||||
|
||||
PostEZCountOne("a stat", "pc@pc.com")
|
||||
p = <-testPostChannel
|
||||
if p.url != "https://api.stathat.com/ez" {
|
||||
t.Errorf("expected ez url")
|
||||
}
|
||||
if p.values.Get("stat") != "a stat" {
|
||||
t.Errorf("expected a stat")
|
||||
}
|
||||
if p.values.Get("ezkey") != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if p.values.Get("count") != "1" {
|
||||
t.Errorf("expected count of 1")
|
||||
}
|
||||
|
||||
PostEZCount("a stat", "pc@pc.com", 213)
|
||||
p = <-testPostChannel
|
||||
if p.url != "https://api.stathat.com/ez" {
|
||||
t.Errorf("expected ez url")
|
||||
}
|
||||
if p.values.Get("stat") != "a stat" {
|
||||
t.Errorf("expected a stat")
|
||||
}
|
||||
if p.values.Get("ezkey") != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if p.values.Get("count") != "213" {
|
||||
t.Errorf("expected count of 213")
|
||||
}
|
||||
|
||||
PostEZValue("a stat", "pc@pc.com", 2.13)
|
||||
p = <-testPostChannel
|
||||
if p.url != "https://api.stathat.com/ez" {
|
||||
t.Errorf("expected ez url")
|
||||
}
|
||||
if p.values.Get("stat") != "a stat" {
|
||||
t.Errorf("expected a stat")
|
||||
}
|
||||
if p.values.Get("ezkey") != "pc@pc.com" {
|
||||
t.Errorf("expected pc@pc.com")
|
||||
}
|
||||
if p.values.Get("value") != "2.13" {
|
||||
t.Errorf("expected value of 2.13")
|
||||
}
|
||||
|
||||
PostCountTime("statkey", "userkey", 13, 100000)
|
||||
p = <-testPostChannel
|
||||
if p.values.Get("t") != "100000" {
|
||||
t.Errorf("expected t value of 100000, got %s", p.values.Get("t"))
|
||||
}
|
||||
|
||||
PostValueTime("statkey", "userkey", 9.312, 200000)
|
||||
p = <-testPostChannel
|
||||
if p.values.Get("t") != "200000" {
|
||||
t.Errorf("expected t value of 200000, got %s", p.values.Get("t"))
|
||||
}
|
||||
|
||||
PostEZCountTime("a stat", "pc@pc.com", 213, 300000)
|
||||
p = <-testPostChannel
|
||||
if p.values.Get("t") != "300000" {
|
||||
t.Errorf("expected t value of 300000, got %s", p.values.Get("t"))
|
||||
}
|
||||
|
||||
PostEZValueTime("a stat", "pc@pc.com", 2.13, 400000)
|
||||
p = <-testPostChannel
|
||||
if p.values.Get("t") != "400000" {
|
||||
t.Errorf("expected t value of 400000, got %s", p.values.Get("t"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user