tile38_mock

package module
v0.0.0-...-6c19410 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

README

Tile38 Mock

This project will make up a mock server for Tile38 that you can define your desired responses with respect of passed command. It can run on a port and you can communicate with it by redis protocol. Best for testing your application with low overhead.

Using

To start using Tile38 Mock install go and get it with:

go get -u github.com/anvari1313/tile38-mock

How to use it

Each instance of tile38_mock.MockServer is responsible for an instance of tile38 server.

  1. First of all import the package
  2. Create a new instance with CreateMockServer.
  3. Set commands and their responses with SetStringResponse.
  4. Init the server with address and port.

Sample Code:

import "github.com/anvari1313/tile38-mock"

...

s := tile38_mock.CreateMockServer() // Create a new mock server instance

// Set command and responses
s.SetStringResponse([]string{"set", "key", "value"}, []string{"OK"})        // SET KEY VALUE -> OK
s.SetStringResponse([]string{"get", "key"}, []string{"VALUE"})              // GET KEY -> VALUE 
s.SetStringResponse([]string{"got", "key"}, []string{"VALUE1", "VALUE1"})   // GOT KEY -> 1)VALUE1 2)VALUE2

_ = s.Init(":1024") // Run the server on port 1024

NOTE: Be aware that tcp server will run in a separate go routine and the init function is non blocking.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockServer

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

func CreateMockServer

func CreateMockServer() *MockServer

func (*MockServer) Init

func (s *MockServer) Init(address string) error

func (*MockServer) SetStringResponse

func (s *MockServer) SetStringResponse(cmd []string, res []string)

Jump to

Keyboard shortcuts

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