func TestPause(t *testing.T) { log.SetOutput(ioutil.Discard) defer log.SetOutput(os.Stdout) _, _, nsqd := mustStartNSQD(NewNSQDOptions()) defer nsqd.Exit() topicName := "test_topic_pause" + strconv.Itoa(int(time.Now().Unix())) topic := nsqd.GetTopic(topicName) err := topic.Pause() assert.Equal(t, err, nil) channel := topic.GetChannel("ch1") assert.NotEqual(t, channel, nil) msg := nsq.NewMessage(<-nsqd.idChan, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaa")) err = topic.PutMessage(msg) assert.Equal(t, err, nil) time.Sleep(15 * time.Millisecond) assert.Equal(t, topic.Depth(), int64(1)) assert.Equal(t, channel.Depth(), int64(0)) err = topic.UnPause() assert.Equal(t, err, nil) time.Sleep(15 * time.Millisecond) assert.Equal(t, topic.Depth(), int64(0)) assert.Equal(t, channel.Depth(), int64(1)) }
func TestParseProjectFromURL(t *testing.T) { project, err := ParseProjectFromURL("https://github.com/jingweno/gh/pulls/21") assert.Equal(t, nil, err) assert.Equal(t, "jingweno", project.Owner) assert.Equal(t, "gh", project.Name) project, err = ParseProjectFromURL("https://github.com/jingweno/gh") assert.Equal(t, nil, err) assert.Equal(t, "jingweno", project.Owner) assert.Equal(t, "gh", project.Name) project, err = ParseProjectFromURL("https://github.com/jingweno/gh/") assert.Equal(t, nil, err) assert.Equal(t, "jingweno", project.Owner) assert.Equal(t, "gh", project.Name) project, err = ParseProjectFromURL("http://github.com/jingweno/gh/") assert.NotEqual(t, nil, err) project, err = ParseProjectFromURL("http://github.com/jingweno/") assert.NotEqual(t, nil, err) }
func TestParseLineCount(t *testing.T) { d := []byte("gorets:2|c|@0.1") packet := parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gorets", packet.Bucket) assert.Equal(t, float64(2), packet.ValFlt) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(0.1), packet.Sampling) d = []byte("gorets:4|c") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gorets", packet.Bucket) assert.Equal(t, float64(4), packet.ValFlt) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("gorets:-4|c") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gorets", packet.Bucket) assert.Equal(t, float64(-4), packet.ValFlt) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("gorets:1.25|c") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gorets", packet.Bucket) assert.Equal(t, 1.25, packet.ValFlt) assert.Equal(t, "c", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) }
func TestSessionStateSerialization(t *testing.T) { c, err := cookie.NewCipher([]byte(secret)) assert.Equal(t, nil, err) c2, err := cookie.NewCipher([]byte(altSecret)) assert.Equal(t, nil, err) s := &SessionState{ Email: "*****@*****.**", AccessToken: "token1234", ExpiresOn: time.Now().Add(time.Duration(1) * time.Hour), RefreshToken: "refresh4321", } encoded, err := s.EncodeSessionState(c) assert.Equal(t, nil, err) assert.Equal(t, 3, strings.Count(encoded, "|")) ss, err := DecodeSessionState(encoded, c) t.Logf("%#v", ss) assert.Equal(t, nil, err) assert.Equal(t, s.Email, ss.Email) assert.Equal(t, s.AccessToken, ss.AccessToken) assert.Equal(t, s.ExpiresOn.Unix(), ss.ExpiresOn.Unix()) assert.Equal(t, s.RefreshToken, ss.RefreshToken) // ensure a different cipher can't decode properly (ie: it gets gibberish) ss, err = DecodeSessionState(encoded, c2) t.Logf("%#v", ss) assert.Equal(t, nil, err) assert.Equal(t, s.Email, ss.Email) assert.Equal(t, s.ExpiresOn.Unix(), ss.ExpiresOn.Unix()) assert.NotEqual(t, s.AccessToken, ss.AccessToken) assert.NotEqual(t, s.RefreshToken, ss.RefreshToken) }
// Test the quit command works... func TestQuit(t *testing.T) { testInit(t) const ( Key1 = "fooz" Val1 = "barz" ) _, err := cn.Set(Key1, Val1, 0, 0, 0) assert.Equalf(t, mcNil, err, "unexpected error: %v", err) v, _, _, err := cn.Get(Key1) assert.Equalf(t, mcNil, err, "unexpected error: %v", err) assert.Equalf(t, Val1, v, "wrong value: %s", v) err = cn.Quit() assert.Equalf(t, mcNil, err, "unexpected error: %v", err) _, _, _, err = cn.Get(Key1) assert.NotEqual(t, mcNil, err, "expected an error (closed connection)") err = cn.Quit() assert.NotEqual(t, mcNil, err, "expected an error (closed connection)") cn = nil }
func TestParseLineTimer(t *testing.T) { d := []byte("glork:320|ms") packet := parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "glork", packet.Bucket) assert.Equal(t, float64(320), packet.ValFlt) assert.Equal(t, "ms", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("glork:320|ms|@0.1") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "glork", packet.Bucket) assert.Equal(t, float64(320), packet.ValFlt) assert.Equal(t, "ms", packet.Modifier) assert.Equal(t, float32(0.1), packet.Sampling) d = []byte("glork:3.7211|ms") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "glork", packet.Bucket) assert.Equal(t, float64(3.7211), packet.ValFlt) assert.Equal(t, "ms", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) }
func TestParseLineGauge(t *testing.T) { d := []byte("gaugor:333|g") packet := parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, GaugeData{false, false, 333}, packet.Value) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("gaugor:-10|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, GaugeData{true, true, 10}, packet.Value) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("gaugor:+4|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, GaugeData{true, false, 4}, packet.Value) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) // >max(int64) && <max(uint64) d = []byte("gaugor:18446744073709551606|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, GaugeData{false, false, 18446744073709551606}, packet.Value) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) }
func TestDoozerWalk(t *testing.T) { l := mustListen() defer l.Close() u := mustListenPacket(l.Addr().String()) defer u.Close() go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9) cl := doozer.New("foo", l.Addr().String()) cl.Set("/test/foo", store.Clobber, []byte("bar")) cl.Set("/test/fun", store.Clobber, []byte("house")) w, err := cl.Walk("/test/**", nil, nil, nil) assert.Equal(t, nil, err, err) ev := <-w.C assert.NotEqual(t, (*doozer.Event)(nil), ev) assert.Equal(t, "/test/foo", ev.Path) assert.Equal(t, "bar", string(ev.Body)) assert.T(t, ev.IsSet()) ev = <-w.C assert.NotEqual(t, (*doozer.Event)(nil), ev) assert.Equal(t, "/test/fun", ev.Path) assert.Equal(t, "house", string(ev.Body)) assert.T(t, ev.IsSet()) ev = <-w.C assert.Tf(t, closed(w.C), "got %v", ev) }
func TestParseURL(t *testing.T) { url, err := ParseURL("https://github.com/jingweno/gh/pulls/21") assert.Equal(t, nil, err) assert.Equal(t, "jingweno", url.Owner) assert.Equal(t, "gh", url.Name) assert.Equal(t, "pulls/21", url.ProjectPath()) url, err = ParseURL("https://github.com/jingweno/gh") assert.Equal(t, nil, err) assert.Equal(t, "jingweno", url.Owner) assert.Equal(t, "gh", url.Name) assert.Equal(t, "", url.ProjectPath()) url, err = ParseURL("https://github.com/jingweno/gh/") assert.Equal(t, nil, err) assert.Equal(t, "jingweno", url.Owner) assert.Equal(t, "gh", url.Name) assert.Equal(t, "", url.ProjectPath()) url, err = ParseURL("http://github.com/jingweno/gh/") assert.NotEqual(t, nil, err) url, err = ParseURL("http://github.com/jingweno/") assert.NotEqual(t, nil, err) }
func TestDelete(t *testing.T) { var didUnsub bool = false unsubf := func(channels ...string) error { assert.Equal(t, "bin_name", channels[0]) didUnsub = true return nil } sm := NewSocketMap(unsubFunc(unsubf)) err := sm.Delete("bin_name", "socket_uuid1") assert.NotEqual(t, nil, err) ms1 := &MockSocket{name: "mock_socket1"} ms2 := &MockSocket{name: "mock_socket2"} sm.Add("bin_name", "socket_uuid1", ms1) sm.Add("bin_name", "socket_uuid2", ms2) err = sm.Delete("bin_name", "unknown_uuid") assert.NotEqual(t, nil, err) err = sm.Delete("unknown_bin_name", "socket_uuid1") assert.NotEqual(t, nil, err) err = sm.Delete("bin_name", "socket_uuid1") assert.Equal(t, nil, err) assert.Equal(t, false, didUnsub) err = sm.Delete("bin_name", "socket_uuid2") assert.Equal(t, nil, err) assert.Equal(t, true, didUnsub) }
func TestDepthFirstSearch(t *testing.T) { G := NewAdjGraphForFile("./algs4-data/tinyG.txt") var search Search var slice []int // test 1 search = NewDepthFirstSearch(G, 0) assert.NotEqual(t, search.Count(), G.V()) slice = make([]int, 0) for v := 0; v < G.V(); v++ { if search.Marked(v) { slice = append(slice, v) } } sort.Ints(slice) assert.Equal(t, slice, []int{0, 1, 2, 3, 4, 5, 6}) // test 2 search = NewDepthFirstSearch(G, 9) assert.NotEqual(t, search.Count(), G.V()) slice = make([]int, 0) for v := 0; v < G.V(); v++ { if search.Marked(v) { slice = append(slice, v) } } sort.Ints(slice) assert.Equal(t, slice, []int{9, 10, 11, 12}) }
func TestSimplejson(t *testing.T) { var ok bool var err error log.SetOutput(ioutil.Discard) js, err := NewJson([]byte(`{ "test": { "array": [1, "2", 3], "int": 10, "float": 5.150, "bignum": 9223372036854775807, "string": "simplejson" } }`)) assert.NotEqual(t, nil, js) assert.Equal(t, nil, err) _, ok = js.CheckGet("test") assert.Equal(t, true, ok) _, ok = js.CheckGet("missing_key") assert.Equal(t, false, ok) arr, _ := js.Get("test").Get("array").Array() assert.NotEqual(t, nil, arr) for i, v := range arr { var iv int switch v.(type) { case float64: iv = int(v.(float64)) case string: iv, _ = strconv.Atoi(v.(string)) } assert.Equal(t, i+1, iv) } i, _ := js.Get("test").Get("int").Int() assert.Equal(t, 10, i) f, _ := js.Get("test").Get("float").Float64() assert.Equal(t, 5.150, f) s, _ := js.Get("test").Get("string").String() assert.Equal(t, "simplejson", s) mi := js.Get("test").Get("int").MustInt() assert.Equal(t, 10, mi) mi2 := js.Get("test").Get("missing_int").MustInt(5150) assert.Equal(t, 5150, mi2) ms := js.Get("test").Get("string").MustString() assert.Equal(t, "simplejson", ms) ms2 := js.Get("test").Get("missing_string").MustString("fyea") assert.Equal(t, "fyea", ms2) }
// 18.4.2. Create Node with properties func TestGetOrCreateNode(t *testing.T) { db := connectTest(t) defer cleanup(t, db) label, err := randutil.String(12, randutil.Alphabet) if err != nil { t.Fatal(err) } key, err := randutil.String(12, randutil.Alphabet) if err != nil { t.Fatal(err) } value, err := randutil.String(12, randutil.Alphabet) if err != nil { t.Fatal(err) } p0 := Props{key: value, "foo": "bar"} p1 := Props{key: value} p2 := Props{"foo": "bar"} // // Create unique node // n0, created, err := db.GetOrCreateNode(label, key, p0) if err != nil { t.Fatal(err) } if !created { t.Fatal("Failed to create unique node") } check0, err := n0.Properties() if err != nil { t.Fatal(err) } assert.Equal(t, p0, check0) // // Get unique node // n1, created, err := db.GetOrCreateNode(label, key, p1) if err != nil { t.Fatal(err) } if created { t.Fatal("Failed to retrieve unique node") } check1, err := n1.Properties() if err != nil { t.Fatal(err) } assert.Equal(t, p0, check1) // // No key in props // _, _, err = db.GetOrCreateNode(label, key, p2) assert.NotEqual(t, nil, err) // // Empty label // _, _, err = db.GetOrCreateNode("", key, p0) assert.NotEqual(t, nil, err) }
func TestMultipleCloses(t *testing.T) { c := NewMockClient() err := c.Close() assert.Equal(t, nil, err) err = c.Close() assert.NotEqual(t, nil, "This should be an error on subsequent closes") err = c.Close() assert.NotEqual(t, nil, "This should be an error on subsequent closes") }
// Tests that jitter adds randomness. func TestJitter(t *testing.T) { defaultBacko := NewBacko(milliseconds(100), 2, 1, milliseconds(10*1000)) jitterBacko := NewBacko(milliseconds(100), 2, 1, milliseconds(10*1000)) // TODO: Check jittered durations are within a range. assert.NotEqual(t, jitterBacko.Duration(0), defaultBacko.Duration(0)) assert.NotEqual(t, jitterBacko.Duration(1), defaultBacko.Duration(1)) assert.NotEqual(t, jitterBacko.Duration(2), defaultBacko.Duration(2)) assert.NotEqual(t, jitterBacko.Duration(3), defaultBacko.Duration(3)) }
func TestServiceMissingData(t *testing.T) { strData := `{"token": "71c12814d8f7095df0bc4881fcd9163c81aede02c1ebc176a548e03a3943cb14", "identifier": 9, "expiry": 3600}` jParsed := make(map[string]interface{}) _ = json.Unmarshal([]byte(strData), &jParsed) result, err := parseApnsJson(jParsed) assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, result) }
func TestGenCheck(t *testing.T) { h, s, err := x.Gen([]byte("bar")) assert.Equal(t, err, nil) assert.NotEqual(t, h, nil) assert.NotEqual(t, s, nil) ok, err := x.Check(x.PwCost, h, []byte("bar"), s) assert.Equal(t, ok, true) assert.Equal(t, err, nil) }
func TestMCSimple(t *testing.T) { nc, err := net.Dial("tcp", mcAddr) assert.Equalf(t, nil, err, "%v", err) cn := &Conn{rwc: nc, buf: new(bytes.Buffer)} if runtime.GOOS != "darwin" { println("Not on Darwin, testing auth") err = cn.Auth("mcgo", "foo") assert.Equalf(t, nil, err, "%v", err) } err = cn.Del("foo") if err != ErrNotFound { assert.Equalf(t, nil, err, "%v", err) } _, _, _, err = cn.Get("foo") assert.Equalf(t, ErrNotFound, err, "%v", err) err = cn.Set("foo", "bar", 0, 0, 0) assert.Equalf(t, nil, err, "%v", err) // unconditional SET err = cn.Set("foo", "bar", 0, 0, 0) assert.Equalf(t, nil, err, "%v", err) err = cn.Set("foo", "bar", 1, 0, 0) assert.Equalf(t, ErrKeyExists, err, "%v", err) v, _, _, err := cn.Get("foo") assert.Equalf(t, nil, err, "%v", err) assert.Equal(t, "bar", v) err = cn.Del("n") if err != ErrNotFound { assert.Equalf(t, nil, err, "%v", err) } n, cas, err := cn.Incr("n", 1, 0, 0) assert.Equalf(t, nil, err, "%v", err) assert.NotEqual(t, 0, cas) assert.Equal(t, 1, n) n, cas, err = cn.Incr("n", 1, 0, 0) assert.Equalf(t, nil, err, "%v", err) assert.NotEqual(t, 0, cas) assert.Equal(t, 2, n) n, cas, err = cn.Decr("n", 1, 0, 0) assert.Equalf(t, nil, err, "%v", err) assert.NotEqual(t, 0, cas) assert.Equal(t, 1, n) }
func TestRunner_splitAliasCmd(t *testing.T) { words, err := splitAliasCmd("!source ~/.zshrc") assert.NotEqual(t, nil, err) words, err = splitAliasCmd("log --pretty=oneline --abbrev-commit --graph --decorate") assert.Equal(t, nil, err) assert.Equal(t, 5, len(words)) words, err = splitAliasCmd("") assert.NotEqual(t, nil, err) }
func TestProcessRequestSuccessFalseWithFailures(t *testing.T) { server, client := setupHttp(200, "application/json", `{"success":"false","message":"Error Message","failures":[{"message":"fail1"},{"message":"fail2"}]}`) defer server.Close() requester := &NetkiRequester{HTTPClient: client} result, err := requester.ProcessRequest(&NetkiPartner{}, "http://domain.com/uri", "GET", "") assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, result) assert.Equal(t, &simplejson.Json{}, result) assert.Equal(t, "Error Message [FAILURES: fail1, fail2]", err.Error()) }
func TestProcessRequestNotJSONData(t *testing.T) { server, client := setupHttp(200, "application/json", "") defer server.Close() requester := &NetkiRequester{HTTPClient: client} result, err := requester.ProcessRequest(&NetkiPartner{}, "http://domain.com/uri", "GET", "") assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, result) assert.Equal(t, &simplejson.Json{}, result) assert.Equal(t, "Error Retrieving JSON Data: EOF", err.Error()) }
func TestGetDomainsError(t *testing.T) { mockRequester := getMockRequester("", &NetkiError{"Error Message", make([]string, 0)}) mockPartner := &NetkiPartner{Requester: mockRequester} domains, err := mockPartner.GetDomains() assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, domains) assert.Equal(t, "Error Message", err.Error()) assert.Equal(t, "/api/domain", mockRequester.calledUri) assert.Equal(t, "GET", mockRequester.calledMethod) assert.Equal(t, "", mockRequester.calledBodyData) assert.Equal(t, 0, len(domains)) }
func TestWebhookSerialization(t *testing.T) { bytes := hooks.ToJSON() assert.NotEqual(t, nil, bytes) assert.NotEqual(t, 0, len(bytes)) hooks2 := WebhookMap{} hooks2.FromJSON(bytes) assert.Equal(t, hooks, hooks2) t.Log("json", string(hooks2.ToJSON())) }
func TestGetDomainDnssecError(t *testing.T) { mockRequester := getMockRequester("", &NetkiError{"Error Message", make([]string, 0)}) mockPartner := &NetkiPartner{Requester: mockRequester} domain, err := mockPartner.GetDomainDnssec(Domain{DomainName: "domain.com"}) assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, domain) assert.Equal(t, "Error Message", err.Error()) assert.Equal(t, "/v1/partner/domain/dnssec/domain.com", mockRequester.calledUri) assert.Equal(t, "GET", mockRequester.calledMethod) assert.Equal(t, "", mockRequester.calledBodyData) assert.Equal(t, "", domain.DomainName) }
func TestSend(t *testing.T) { sm := NewSocketMap(getUnsubFunc(t)) err := sm.Send("bin_name", []byte("a message")) assert.NotEqual(t, nil, err) ms := &MockSocket{name: "mock_socket"} sm.Add("bin_name", "socket_uuid", ms) err = sm.Send("unknown_bin_name", []byte("a message")) assert.NotEqual(t, nil, err) err = sm.Send("bin_name", []byte("a message")) assert.Equal(t, nil, err) // sleep a bit to allow go routines to be scheduled and run time.Sleep(25 * time.Microsecond) assert.Equal(t, true, ms.getDidWrite()) }
func TestInvalidUrl(t *testing.T) { // // Missing protocol scheme - url.Parse should fail // url := "://foobar.com" _, err := Get(url, nil, nil, nil) assert.NotEqual(t, nil, err) // // Unsupported protocol scheme - HttpClient.Do should fail // url = "foo://bar.com" _, err = Get(url, nil, nil, nil) assert.NotEqual(t, nil, err) }
func TestParseLineGauge(t *testing.T) { d := []byte("gaugor:333|g") packet := parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, float64(333), packet.ValFlt) assert.Equal(t, "", packet.ValStr) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("gaugor:-10|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, float64(10), packet.ValFlt) assert.Equal(t, "-", packet.ValStr) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) d = []byte("gaugor:+4|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, float64(4), packet.ValFlt) assert.Equal(t, "+", packet.ValStr) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) // >max(int64) && <max(uint64) d = []byte("gaugor:18446744073709551606|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, float64(18446744073709551606), packet.ValFlt) assert.Equal(t, "", packet.ValStr) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) // float values d = []byte("gaugor:3.3333|g") packet = parseLine(d) assert.NotEqual(t, packet, nil) assert.Equal(t, "gaugor", packet.Bucket) assert.Equal(t, float64(3.3333), packet.ValFlt) assert.Equal(t, "", packet.ValStr) assert.Equal(t, "g", packet.Modifier) assert.Equal(t, float32(1), packet.Sampling) }
func TestDoozerGet(t *testing.T) { l := mustListen() defer l.Close() u := mustListenUDP(l.Addr().String()) defer u.Close() go Main("a", "X", "", "", "", nil, u, l, nil, 1e9, 2e9, 3e9, 101) cl := dial(l.Addr().String()) _, err := cl.Set("/x", store.Missing, []byte{'a'}) assert.Equal(t, nil, err) ents, rev, err := cl.Get("/x", nil) assert.Equal(t, nil, err) assert.NotEqual(t, store.Dir, rev) assert.Equal(t, []byte{'a'}, ents) //cl.Set("/test/a", store.Missing, []byte{'1'}) //cl.Set("/test/b", store.Missing, []byte{'2'}) //cl.Set("/test/c", store.Missing, []byte{'3'}) //ents, rev, err = cl.Get("/test", 0) //sort.SortStrings(ents) //assert.Equal(t, store.Dir, rev) //assert.Equal(t, nil, err) //assert.Equal(t, []string{"a", "b", "c"}, ents) }
func TestLinkedInProviderOverrides(t *testing.T) { p := NewLinkedInProvider( &ProviderData{ LoginURL: &url.URL{ Scheme: "https", Host: "example.com", Path: "/oauth/auth"}, RedeemURL: &url.URL{ Scheme: "https", Host: "example.com", Path: "/oauth/token"}, ProfileURL: &url.URL{ Scheme: "https", Host: "example.com", Path: "/oauth/profile"}, ValidateURL: &url.URL{ Scheme: "https", Host: "example.com", Path: "/oauth/tokeninfo"}, Scope: "profile"}) assert.NotEqual(t, nil, p) assert.Equal(t, "LinkedIn", p.Data().ProviderName) assert.Equal(t, "https://example.com/oauth/auth", p.Data().LoginURL.String()) assert.Equal(t, "https://example.com/oauth/token", p.Data().RedeemURL.String()) assert.Equal(t, "https://example.com/oauth/profile", p.Data().ProfileURL.String()) assert.Equal(t, "https://example.com/oauth/tokeninfo", p.Data().ValidateURL.String()) assert.Equal(t, "profile", p.Data().Scope) }
func TestConnNotify(t *testing.T) { nc, err := net.Dial("tcp", "localhost:5432") assert.Equalf(t, nil, err, "%v", err) cn, err := New(nc, map[string]string{"user": os.Getenv("USER")}, "") assert.Equalf(t, nil, err, "%v", err) // Listen lstmt, err := cn.Prepare("LISTEN test") assert.Equalf(t, nil, err, "%v", err) _, err = lstmt.Exec(nil) assert.Equalf(t, nil, err, "%v", err) err = lstmt.Close() assert.Equalf(t, nil, err, "%v", err) // Notify nstmt, err := cn.Prepare("NOTIFY test, 'foo'") assert.Equalf(t, nil, err, "%v", err) _, err = nstmt.Exec(nil) assert.Equalf(t, nil, err, "%v", err) err = nstmt.Close() assert.Equalf(t, nil, err, "%v", err) n := <-cn.Notifies assert.NotEqual(t, 0, n.Pid) assert.Equal(t, "test", n.From) assert.Equal(t, "foo", n.Payload) }