testclient

package
v0.0.0-...-4f83aec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewActionList

func NewActionList(cl Client) []gentest.Actor

NewActionList creates a slice of the clients actors.

func NewRMessage

func NewRMessage(name string, text string, done chan bool) *rMessage

NewRMessage creates a new rMessage.

func NewRestActionList

func NewRestActionList(cl *RestClient) []gentest.Actor

NewRestActionList creates a slice of rest client actors.

func RandomString

func RandomString(maxlen int) string

RandomString returns a random string of maxlen > len > 0 made up of upper and lower case letters and/or numbers.

func RemoveTime

func RemoveTime(s string) string

RemoveTime removes the time from a message string from the server to make it easier to compare with the results.

Types

type Client

type Client interface {
	Login()
	Block(string)
	UnBlock(string)
	Who(string)
	List()
	Join(string)
	Send(string)
	CheckResponse()
	Name() string
	Update()
}

Client is an interface for using the ChatTest including all the functions that it calls

type ClientData

type ClientData struct {
	Rooms   []string
	Names   []string
	Clients []SharedClient
}

ClientData is an object for passing the necessary data into the actions.

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient is a Client used for testing the server's HTTP side.

func NewHTTPClient

func NewHTTPClient(name string, ip string, port string, rh *ResultHandler, t *testing.T) *HTTPClient

NewHTTPClient returns a new http client.

func (*HTTPClient) Block

func (cl *HTTPClient) Block(name string)

Block adds the name to client's block list and updates its results.

func (*HTTPClient) CheckResponse

func (cl *HTTPClient) CheckResponse()

CheckResponse compares the clients messages recieved to those expected by its Results object and fails the test if they don't match. It also panics to short circuit long tests when it goes out of sync.

func (*HTTPClient) GetMessages

func (cl *HTTPClient) GetMessages()

GetMessages retrieves the clients current messages from the server.

func (*HTTPClient) Join

func (cl *HTTPClient) Join(rmName string)

Join adds the client to a room and updates its results.

func (*HTTPClient) List

func (cl *HTTPClient) List()

List retrieves from the server a list of current rooms and updates its results.

func (*HTTPClient) Login

func (cl *HTTPClient) Login()

Login connects the client to the server and sets the clients token for future requests.

func (*HTTPClient) Name

func (cl *HTTPClient) Name() string

Name returns the name of the client.

func (*HTTPClient) Send

func (cl *HTTPClient) Send(msg string)

Send transmits the message to the clients room and updates its results.

func (*HTTPClient) UnBlock

func (cl *HTTPClient) UnBlock(name string)

Unblock removes clients matching name from this client's block list and updates its results.

func (*HTTPClient) Update

func (cl *HTTPClient) Update()

Update runs GetMessage to update the client's messages from the server.

func (*HTTPClient) Who

func (cl *HTTPClient) Who(rmName string)

Who retrieves from the server a list of the clients currently in the room and updates its results.

type Lgn

type Lgn struct {
	Name     string
	Password string
}

type RestClient

type RestClient struct {
	// contains filtered or unexported fields
}

RestClient is a type of client for testing the servers REST api.

func NewRestClient

func NewRestClient(name string, ip string, port string, rh *ResultHandler, t *testing.T) *RestClient

NewRestClient returns a new RestClient.

func (*RestClient) CheckResponse

func (cl *RestClient) CheckResponse()

CheckResponse checks to see if the next message in the clients messages list is equal to m.

func (*RestClient) Get

func (cl *RestClient) Get(room string)

Get gets the messages from the room.

func (RestClient) Name

func (cl RestClient) Name() string

Name returns the name of the client.

func (*RestClient) Send

func (cl *RestClient) Send(m, room string)

Send sends the message to the room.

func (*RestClient) Update

func (cl *RestClient) Update()

Update is empty so that a rest client can meet the Client interface. A rest client can not be updated because it doesn't expect anything specific from the server.

type Result

type Result struct {
	Results []string
	// contains filtered or unexported fields
}

Result is an object for keeping track of what responses the client should be getting from the server. Result.Results contains all of the messages that should have been sent to the client.

func NewResult

func NewResult(name string, rh *ResultHandler) *Result

NewResult creates a new result object without a chattest.

func (*Result) Add

func (r *Result) Add(text string)

Add adds the string to the Result of only this Result not the others in the same room.

func (*Result) Block

func (r *Result) Block(name string)

Block adds name to the Result's blocklist.

func (*Result) GetRoom

func (r *Result) GetRoom(rm string) *room

GetRoom returns a room with name matching rm. Unlike join it will not create one if it doesn't exist, returning nil instead.

func (*Result) IsBlocked

func (r *Result) IsBlocked(name string) bool

IsBlocked checks to see if name is in the result blocklist.

func (*Result) Join

func (r *Result) Join(rm string)

Join changes the results room to the with name == rm and updates its channels.

func (*Result) JoinSend

func (r *Result) JoinSend(text string)

JoinSend adds the string to the results of everyone in the same room as the sender even if blocking the sender. Primarily for use with join room messages.

func (*Result) List

func (r *Result) List()

List udpates the result for a list action, adding the list of current rooms in the Result.

func (*Result) RestGet

func (r *Result) RestGet(name string)

RestGet updates the Result for a rest client getting messages.

func (*Result) RestSend

func (r *Result) RestSend(message, room string)

RestSend updates all results for a rest client sending a message.

func (*Result) Room

func (r *Result) Room() string

Room returns the name of the room the Result is currently "in."

func (*Result) Send

func (r *Result) Send(text string)

Send adds the string to the results of everyone in the same room as the sender.

func (*Result) UnBlock

func (r *Result) UnBlock(name string) bool

UnBlock removes the name from the Result's blocklist.

func (*Result) Who

func (r *Result) Who(name string)

Who updates the Result for a who action. It adds the list of people in the specified room in the Result.

type ResultHandler

type ResultHandler struct {
	// contains filtered or unexported fields
}

ResultHandler manages the result rooms and the interactions between the results of different clients.

func NewResultHandler

func NewResultHandler() *ResultHandler

NewResultHandler creates a new ResultHandler.

type SharedClient

type SharedClient interface {
	Update()
	CheckResponse()
}

SharedClient is an interface for use in the shared ClientData

type TelnetClient

type TelnetClient struct {
	// contains filtered or unexported fields
}

TelnetClient is a Client used for testing the server's telnet side.

func NewTelnetClient

func NewTelnetClient(name string, ip string, port string, rh *ResultHandler, t *testing.T) *TelnetClient

NewTelnetClient returns a new telnet client.

func (*TelnetClient) Block

func (cl *TelnetClient) Block(name string)

Block adds name to client's block list and updates its results.

func (*TelnetClient) CheckResponse

func (cl *TelnetClient) CheckResponse()

CheckResponse compares the clients messages recieved to those expected by its Results object and fails the test if they don't match. It also panics to short circuit long tests when it goes out of sync.

func (*TelnetClient) GetMessages

func (cl *TelnetClient) GetMessages()

GetMessages reads the messages from the server and stores them in the clients messages

func (*TelnetClient) Join

func (cl *TelnetClient) Join(rm string)

Join adds the client to a room and updates its results.

func (*TelnetClient) List

func (cl *TelnetClient) List()

List retrieves from the server a list of current rooms and updates its results.

func (*TelnetClient) Login

func (cl *TelnetClient) Login()

Login connects the client to the server and starts GetMessages, its messages retrieval method.

func (TelnetClient) Name

func (cl TelnetClient) Name() string

Name returns the clients name.

func (*TelnetClient) Send

func (cl *TelnetClient) Send(m string)

Send transmits the message to the clients room and updates its results.

func (*TelnetClient) UnBlock

func (cl *TelnetClient) UnBlock(name string)

UnBlock removes clients matching name from this client's block list and updates its results.

func (*TelnetClient) Update

func (cl *TelnetClient) Update()

Update is a method that runs checkupdate to match with the Client interface.

func (*TelnetClient) Who

func (cl *TelnetClient) Who(rm string)

Who retrieves from the server a list of the clients currently in the room and updates its results.

type TestClient

type TestClient struct {
	// contains filtered or unexported fields
}

TestClient can hold either a regular client or a rest client. The client that it uses is determined by its action.

func NewTestClient

func NewTestClient(cl Client) *TestClient

NewTestClient returns a test client with default equal weights for its actions.

func NewTestClientWithWeights

func NewTestClientWithWeights(cl Client, weights []int) *TestClient

NewTestClientWithWeights returns a test client with weighted action probabilites. The weights slice should contain int for the weights in the order of join, send, block, unblock, list, who.

func NewTestRestClient

func NewTestRestClient(cl *RestClient) *TestClient

NewTestRestClient returns a test client that uses the rest inteface with default weights for its actions.

func (*TestClient) Client

func (tc *TestClient) Client() SharedClient

Client() returns the TestClient's Client.

func (*TestClient) Do

func (tc *TestClient) Do(shared interface{}) string

Do is a method that allows the test client to meet the Actor interface. It will run a random client action from its action list.

type TestMessage

type TestMessage struct {
	Name string
	Text string
}

TestMessage is a simple message implementation for use by the RestClient in composing messages for transmission to the server.

func (TestMessage) Result

func (t TestMessage) Result() string

Result returns a string of the message in the format used by the server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL