test_server

package
v0.0.0-...-07cd16e Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: MIT Imports: 11 Imported by: 0

README

Test Server

This is a mock Akka (and legacy obaku) server. It will start a server and handle requests and return JSON objects back. However, there are some basics you will need to know in order to use it

Setup

To use the test server, you will need to create a sample directory under your repo. So, let's use the example below.

my_app/
  sample/
    upload.json
    v2/
      login.json
      upload.json
  main.go

Some of them don't all fall into the v2 category, so you'll have to look at the handleV1 and handleV2 functions to see how its loaded

Usage

You can see some basic examples but also look at the tests in SYNQ-Golang/synq for many other practical examples.

import (
  "http"

  "github.com/SYNQfm/SYNQ-Golang/test_server"
)

# create a "v2" server (supports Akka)
server := test_server.ServerServer("v2")
url := server.GetUrl()

# get all videos
resp, err := http.Get(url + "/v1/videos")

# Get a specific video, with global video ids used by the server
# For instance V2_VIDEO_ID, is the valid id that you would call the get/upload apis for
resp, err := http.Get(url + "/v1/videos/"+test_server.V2_VIDEO_ID)

# get the req and body values
reqs, vals := server.GetReqs()

# this is an array of url.Values, which has a single "body" key
req_body := vals[0].Get("body")[0]
json.Unmarshal(req_body, &obj)

# Get the last intiated server's reqs, since typically you only create one server per test
reqs, vals := test_server.GetReqs()

There's also helper function under SYNQ-Golang/helper/setup.go that will set an api object using the test server, see the code below

func SetupForTestV2() synq.ApiV2 {
  server := test_server.SetupServer(SYNQ_VERSION)
  url := server.GetUrl()
  api := synq.NewV2(test_server.TEST_AUTH)
  api.SetUrl(url)
  return api
}

Documentation

Index

Constants

View Source
const (
	UPLOAD_KEY          = "projects/0a/bf/0abfe1b849154082993f2fce77a16fd9/uploads/videos/55/d4/55d4062f99454c9fb21e5186a09c2115.mp4"
	V2_INVALID_AUTH     = `{"message" : "invalid auth"}`
	V2_VIDEO_ID         = "9e9dc8c8-f705-41db-88da-b3034894deb9"
	V2_VIDEO_ID2        = "eee2bc43-e973-4f73-857d-7c0bb111a834"
	ASSET_ID            = "01823629-bcf2-4c34-b714-ae21e1a4647f"
	ASSET_ID2           = "fc3e5d9a-a90e-49cc-0c67-224372a59cee"
	TRAILER_ID          = "40669c19-85aa-4c0d-9b88-ea3c3b20e514"
	TEST_AUTH           = "" /* 277-byte string literal not displayed */
	DEFAULT_AWS_SECRET  = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY"
	ACCOUNT_ID          = "425b6b3b-f272-4a33-da4c-19d846685211"
	SETTINGS_NAME       = "widevine"
	DEFAULT_SAMPLE_DIR  = "sample"
	SYNQ_VERSION        = "v2"
	SYNQ_ROUTE          = "v1"
	SYNQ_LEGACY_VERSION = "v1"
	SYNQ_LEGACY_ROUTE   = "v1"
)

Variables

View Source
var UploadError error

Functions

func CloseAll

func CloseAll()

func GetParams

func GetParams() []upload.UploadParameters

func GetReqs

func GetReqs() ([]*http.Request, []url.Values)

func LoadSampleDir

func LoadSampleDir(name string, dir string, dataOnMissing ...[]byte) (data []byte)

func NewTestAwsUpload

func NewTestAwsUpload(params upload.UploadParameters) (upload.AwsUploadF, error)

func ResetReqs

func ResetReqs()

func SetSampleDir

func SetSampleDir(sampleDir string)

Types

type TestAwsUpload

type TestAwsUpload struct {
}

func (TestAwsUpload) Upload

func (t TestAwsUpload) Upload(body io.Reader) (*s3manager.UploadOutput, error)

type TestServer

type TestServer struct {
	Version   string
	SampleDir string
	Server    *httptest.Server
	Reqs      []*http.Request
	Values    []url.Values
}

func LastServer

func LastServer() *TestServer

func SetupServer

func SetupServer(args ...string) *TestServer

func (*TestServer) Close

func (t *TestServer) Close()

func (*TestServer) GetReqs

func (s *TestServer) GetReqs() ([]*http.Request, []url.Values)

func (*TestServer) GetUrl

func (t *TestServer) GetUrl() string

func (*TestServer) LoadSample

func (t *TestServer) LoadSample(name string) (data []byte)

legacy sample loader still used by v2/synq media

func (*TestServer) LoadSampleV2

func (t *TestServer) LoadSampleV2(name string) []byte

func (*TestServer) Reset

func (t *TestServer) Reset()

func (*TestServer) Setup

func (s *TestServer) Setup() string

Jump to

Keyboard shortcuts

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