本文整理匯總了Golang中github.com/centrifugal/centrifugo/Godeps/_workspace/src/github.com/stretchr/testify/assert.NotEqual函數的典型用法代碼示例。如果您正苦於以下問題:Golang NotEqual函數的具體用法?Golang NotEqual怎麽用?Golang NotEqual使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NotEqual函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRemotePrecedence
func TestRemotePrecedence(t *testing.T) {
initJSON()
remote := bytes.NewReader(remoteExample)
assert.Equal(t, "0001", Get("id"))
marshalReader(remote, v.kvstore)
assert.Equal(t, "0001", Get("id"))
assert.NotEqual(t, "cronut", Get("type"))
assert.Equal(t, "remote", Get("newkey"))
Set("newkey", "newvalue")
assert.NotEqual(t, "remote", Get("newkey"))
assert.Equal(t, "newvalue", Get("newkey"))
Set("newkey", "remote")
}
示例2: TestClientUpdatePresence
func TestClientUpdatePresence(t *testing.T) {
app := testApp()
c, err := newClient(app, &testSession{})
assert.Equal(t, nil, err)
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
cmds := []clientCommand{testConnectCmd(timestamp), testSubscribeCmd("test1"), testSubscribeCmd("test2")}
err = c.handleCommands(cmds)
assert.Equal(t, nil, err)
assert.Equal(t, 2, len(c.channels()))
assert.NotEqual(t, nil, c.presenceTimer)
timer := c.presenceTimer
c.updatePresence()
assert.NotEqual(t, timer, c.presenceTimer)
}
示例3: TestClientMessage
func TestClientMessage(t *testing.T) {
app := testApp()
c, err := newClient(app, &testSession{})
assert.Equal(t, nil, err)
// empty message
err = c.message([]byte{})
assert.Equal(t, ErrInvalidMessage, err)
// malformed message
err = c.message([]byte("wroooong"))
assert.NotEqual(t, nil, err)
var cmds []clientCommand
nonConnectFirstCmd := clientCommand{
Method: "subscribe",
Params: []byte("{}"),
}
cmds = append(cmds, nonConnectFirstCmd)
cmdBytes, err := json.Marshal(cmds)
assert.Equal(t, nil, err)
err = c.message(cmdBytes)
assert.Equal(t, ErrUnauthorized, err)
}
示例4: TestAdminClient
func TestAdminClient(t *testing.T) {
c, err := newTestAdminClient()
go c.writer()
assert.Equal(t, nil, err)
assert.NotEqual(t, c.uid(), "")
err = c.send([]byte("message"))
assert.Equal(t, nil, err)
}
示例5: TestMemoryEngine
func TestMemoryEngine(t *testing.T) {
e := testMemoryEngine()
assert.NotEqual(t, nil, e.historyHub)
assert.NotEqual(t, nil, e.presenceHub)
assert.NotEqual(t, e.name(), "")
assert.Equal(t, nil, e.publish(ChannelID("channel"), []byte("{}")))
assert.Equal(t, nil, e.subscribe(ChannelID("channel")))
assert.Equal(t, nil, e.unsubscribe(ChannelID("channel")))
assert.Equal(t, nil, e.addPresence(ChannelID("channel"), "uid", ClientInfo{}))
p, err := e.presence(ChannelID("channel"))
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(p))
assert.Equal(t, nil, e.addHistory(ChannelID("channel"), Message{}, 1, 1))
h, err := e.history(ChannelID("channel"))
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(h))
}
示例6: TestLevels
func TestLevels(t *testing.T) {
SetStdoutThreshold(LevelError)
assert.Equal(t, outputThreshold, LevelError)
SetLogThreshold(LevelCritical)
assert.Equal(t, logThreshold, LevelCritical)
assert.NotEqual(t, outputThreshold, LevelCritical)
SetStdoutThreshold(LevelWarn)
assert.Equal(t, outputThreshold, LevelWarn)
}
示例7: TestClientConnect
func TestClientConnect(t *testing.T) {
app := testApp()
c, err := newClient(app, &testSession{})
assert.Equal(t, nil, err)
var cmd clientCommand
var cmds []clientCommand
cmd = clientCommand{
Method: "connect",
Params: []byte(`{"project": "test1"}`),
}
cmds = []clientCommand{cmd}
err = c.handleCommands(cmds)
assert.Equal(t, ErrInvalidToken, err)
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
cmds = []clientCommand{testConnectCmd(timestamp)}
err = c.handleCommands(cmds)
assert.Equal(t, nil, err)
assert.Equal(t, true, c.authenticated)
ts, err := strconv.Atoi(timestamp)
assert.Equal(t, int64(ts), c.timestamp)
clientInfo := c.info(Channel(""))
assert.Equal(t, UserID("user1"), clientInfo.User)
assert.Equal(t, 1, len(app.clients.conns))
assert.NotEqual(t, "", c.uid(), "uid must be already set")
assert.NotEqual(t, "", c.user(), "user must be already set")
err = c.clean()
assert.Equal(t, nil, err)
assert.Equal(t, 0, len(app.clients.conns))
}
示例8: TestAdminClientMessageHandling
func TestAdminClientMessageHandling(t *testing.T) {
c, err := newTestAdminClient()
assert.Equal(t, nil, err)
emptyMsg := ""
_, err = c.handleMessage([]byte(emptyMsg))
assert.NotEqual(t, nil, err)
malformedMsg := "ooops"
_, err = c.handleMessage([]byte(malformedMsg))
assert.NotEqual(t, nil, err)
unknownMsg := "{\"method\":\"unknown\", \"params\": {}}"
_, err = c.handleMessage([]byte(unknownMsg))
assert.Equal(t, ErrInvalidMessage, err)
emptyAuthMethod := "{\"method\":\"auth\", \"params\": {}}"
_, err = c.handleMessage([]byte(emptyAuthMethod))
assert.Equal(t, ErrUnauthorized, err)
s := securecookie.New([]byte(c.app.config.WebSecret), nil)
token, _ := s.Encode(AuthTokenKey, AuthTokenValue)
correctAuthMethod := "{\"method\":\"auth\", \"params\": {\"token\":\"" + token + "\"}}"
_, err = c.handleMessage([]byte(correctAuthMethod))
assert.Equal(t, nil, err)
pingCommand := "{\"method\":\"ping\", \"params\": {}}"
_, err = c.handleMessage([]byte(pingCommand))
assert.Equal(t, nil, err)
}
示例9: TestRawWsHandler
func TestRawWsHandler(t *testing.T) {
app := testApp()
mux := DefaultMux(app, DefaultMuxOptions)
server := httptest.NewServer(mux)
defer server.Close()
url := "ws" + server.URL[4:]
conn, resp, err := websocket.DefaultDialer.Dial(url+"/connection/websocket", nil)
conn.Close()
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, conn)
assert.Equal(t, http.StatusSwitchingProtocols, resp.StatusCode)
app.Shutdown()
_, resp, err = websocket.DefaultDialer.Dial(url+"/connection/websocket", nil)
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
}
示例10: TestUnauthenticatedClient
func TestUnauthenticatedClient(t *testing.T) {
app := testApp()
c, err := newClient(app, &testSession{})
assert.Equal(t, nil, err)
assert.NotEqual(t, "", c.uid())
// user not set before connect command success
assert.Equal(t, UserID(""), c.user())
assert.Equal(t, false, c.authenticated)
assert.Equal(t, []Channel{}, c.channels())
// check that unauthenticated client can be cleaned correctly
err = c.clean()
assert.Equal(t, nil, err)
}
示例11: TestAdminWebsocketHandler
func TestAdminWebsocketHandler(t *testing.T) {
app := testApp()
mux := DefaultMux(app, "", "path/to/web", "sockjs url")
server := httptest.NewServer(mux)
defer server.Close()
url := "ws" + server.URL[4:]
conn, resp, err := websocket.DefaultDialer.Dial(url+"/socket", nil)
data := map[string]interface{}{
"method": "ping",
"params": map[string]string{},
}
conn.WriteJSON(data)
var response interface{}
conn.ReadJSON(&response)
conn.Close()
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, conn)
assert.Equal(t, http.StatusSwitchingProtocols, resp.StatusCode)
}
示例12: TestAdminWebsocketHandler
func TestAdminWebsocketHandler(t *testing.T) {
app := testApp()
app.config.Web = true // admin websocket available only if web enabled at moment
opts := DefaultMuxOptions
opts.Web = true
mux := DefaultMux(app, opts)
server := httptest.NewServer(mux)
defer server.Close()
url := "ws" + server.URL[4:]
conn, resp, err := websocket.DefaultDialer.Dial(url+"/socket", nil)
data := map[string]interface{}{
"method": "ping",
"params": map[string]string{},
}
conn.WriteJSON(data)
var response interface{}
conn.ReadJSON(&response)
conn.Close()
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, conn)
assert.Equal(t, http.StatusSwitchingProtocols, resp.StatusCode)
}
示例13: TestMemoryEngine
func TestMemoryEngine(t *testing.T) {
e := testMemoryEngine()
err := e.run()
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, e.historyHub)
assert.NotEqual(t, nil, e.presenceHub)
assert.NotEqual(t, e.name(), "")
err = e.publish(ChannelID("channel"), []byte("{}"), nil)
assert.Equal(t, nil, err)
assert.Equal(t, nil, e.subscribe(ChannelID("channel")))
// Memory engine is actually tightly coupled to application hubs in implementation
// so calling subscribe on the engine alone is actually a no-op since Application already
// knows about the subscription.
// In order to test publish works after subscription is added, we actually need to inject a
// fake subscription into the Application hub
fakeConn := &TestConn{"test", "test", []Channel{"channel"}}
e.app.clients.addSub(ChannelID("channel"), fakeConn)
// Now we've subscribed...
err = e.publish(ChannelID("channel"), []byte("{}"), nil)
assert.Equal(t, nil, err)
assert.Equal(t, nil, e.unsubscribe(ChannelID("channel")))
// Same dance to manually remove sub from app hub
e.app.clients.removeSub(ChannelID("channel"), fakeConn)
assert.Equal(t, nil, e.addPresence(ChannelID("channel"), "uid", ClientInfo{}))
p, err := e.presence(ChannelID("channel"))
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(p))
err = e.removePresence(ChannelID("channel"), "uid")
assert.Equal(t, nil, err)
msg := Message{UID: MessageID("test UID")}
msgJSON, _ := json.Marshal(msg)
// test adding history
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 4, 1, false}))
h, err := e.history(ChannelID("channel"), historyOpts{})
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(h))
assert.Equal(t, h[0].UID, MessageID("test UID"))
// test history limit
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 4, 1, false}))
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 4, 1, false}))
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 4, 1, false}))
h, err = e.history(ChannelID("channel"), historyOpts{Limit: 2})
assert.Equal(t, nil, err)
assert.Equal(t, 2, len(h))
// test history limit greater than history size
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 1, 1, false}))
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 1, 1, false}))
assert.Equal(t, nil, e.publish(ChannelID("channel"), msgJSON, &publishOpts{msg, 1, 1, false}))
h, err = e.history(ChannelID("channel"), historyOpts{Limit: 2})
// HistoryDropInactive tests - new channel to avoid conflicts with test above
// 1. add history with DropInactive = true should be a no-op if history is empty
assert.Equal(t, nil, e.publish(ChannelID("channel-2"), msgJSON, &publishOpts{msg, 2, 5, true}))
h, err = e.history(ChannelID("channel-2"), historyOpts{})
assert.Equal(t, nil, err)
assert.Equal(t, 0, len(h))
// 2. add history with DropInactive = false should always work
assert.Equal(t, nil, e.publish(ChannelID("channel-2"), msgJSON, &publishOpts{msg, 2, 5, false}))
h, err = e.history(ChannelID("channel-2"), historyOpts{})
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(h))
// 3. add with DropInactive = true should work immediately since there should be something in history
// for 5 seconds from above
assert.Equal(t, nil, e.publish(ChannelID("channel-2"), msgJSON, &publishOpts{msg, 2, 5, true}))
h, err = e.history(ChannelID("channel-2"), historyOpts{})
assert.Equal(t, nil, err)
assert.Equal(t, 2, len(h))
}
示例14: TestSetLogFile
func TestSetLogFile(t *testing.T) {
err := SetLogFile("/tmp/testing")
assert.Equal(t, nil, err)
err = SetLogFile("/i_want_it_to_not_exist_so_error_return/testing")
assert.NotEqual(t, nil, err)
}
示例15: TestMediator
func TestMediator(t *testing.T) {
app := testApp()
m := &testMediator{}
app.SetMediator(m)
assert.NotEqual(t, nil, app.mediator)
}