pica

package module
v0.0.0-...-4c9cbb9 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pica

Build Status go report

Pica is a restful automated testing tool and document generate tool written in golang.

It's inspired deeply by frank.

Features

  • Basic api test (support POST, GET, PUT, DELETE, PATCH)
  • Generate api document to markdown file.
  • Benchmark webapi.(TODO)
  • Serve api document as a website.(TODO)
    • Custom theme or css for this website(TODO).
  • Api version controls, automated version release note.
  • Api version diff to show.(TODO)

screenshots/1.jpg screenshots/2.jpg

Status

It's under development.

Install

go get github.com/jerloo/pica/cmd/pica

Usage

// It's a full demo for pica.

// Init vars
name = 'demo'
description = 'This is a demo for pica.'
version = '0.0.1'
author = 'jerloo@gmail.com jerloo'
baseUrl = 'http://localhost:8080'

headers = {
    'Content-Type' = 'application/json'
}

// Apis format: [method] [path] [description]

// GET /api/users 获取用户列表
headers['Authorization'] = 'slfjaslkfjlasdjfjas=='

// POST /api/users 新建用户
post = {
    // 用户名
    'name' = 'test'
    // 密码
    'age' = 10
}
$ pica --help

usage: pica [<flags>] <command> [<args> ...]

A command line for api test and doc generate.

Flags:
  --help   Show context-sensitive help (also try --help-long and --help-man).
  --debug  Debug mode.

Commands:
  help [<command>...]
    Show help.

  run [<flags>] [<filename>] [<apiNames>...]
    Run api file.

  format [<flags>] [<filename>]
    Format api file.

  serve [<flags>]
    Run a document website.

  init [<filename>] [<template>]
    Init a new api file from template.

  config [<flags>]
    Config pica.


TODO

  • Document generation
  • Api document server
  • Api document version control
  • Add funny grammer provider

LICENSE

The MIT License (MIT)

Copyright (c) 2018 jerloo

Documentation

Index

Constants

View Source
const (
	Version = "0.0.1"
)

Variables

View Source
var DEFAULT_DOC_TEMPLATE = ""
View Source
var DefaultHeaders = map[string]funny.Value{
	"Accept":          "* /*",
	"Accept-Language": "en-US,en;q=0.8",
	"Cache-Control":   "max-age=0",
	"User-Agent":      fmt.Sprintf("Pica Api Test Client/%s https://github.com/jerloo/pica", Version),
	"Connection":      "keep-alive",
	"Referer":         "http://www.baidu.com/",
	"Content-Type":    "application/json",
}
View Source
var DefaultInitScope = map[string]funny.Value{
	"headers": DefaultHeaders,
}
View Source
var (
	DefaultOutput = NewOutput(true, os.Stdout)
)
View Source
var GenFromPostmanTemplate string
View Source
var PROFILE_HOME = ""

Functions

func Address

func Address(interpreter *funny.Funny, args []funny.Value) funny.Value

Address builtin function to fake an address

func BuildHTML

func BuildHTML(input []byte) string

func Capitalize

func Capitalize(str string) string

字符首字母大写转换

func CreateHttpRequest

func CreateHttpRequest(req *ApiRequest, runner *APIRunner) (httpReq *http.Request, err error)

func Domain

func Domain(interpreter *funny.Funny, args []funny.Value) funny.Value

Domain builtin function to fake a domain

func Email

func Email(interpreter *funny.Funny, args []funny.Value) funny.Value

Email builtin function to fake an email

func Format

func Format(filename string, save, print bool) (string, error)

func FullName

func FullName(interpreter *funny.Funny, args []funny.Value) funny.Value

FullName builtin function to fake a fullname

func GenDocument

func GenDocument(apiRunner *APIRunner, output string) error

func HttpHeaders2VmMap

func HttpHeaders2VmMap(httpHeader http.Header) map[string]funny.Value

func Init

func Init(filename, templateName string) error

func Phone

func Phone(interpreter *funny.Funny, args []funny.Value) funny.Value

Phone builtin function to fake a phone no

func Serve

func Serve(filename string, port int) error

func TSafeJson

func TSafeJson(obj interface{}) string

func VersionCommit

func VersionCommit(commitFile, commitMsg string)

func VersionLog

func VersionLog(filename string)

func VmMap2HttpHeaders

func VmMap2HttpHeaders(vmMap map[string]funny.Value) http.Header

func Words

func Words(interpreter *funny.Funny, args []funny.Value) funny.Value

Words builtin function to fake words

Types

type APIRunner

type APIRunner struct {
	Filename string
	APINames []string
	Delay    int

	APIItems  []*ApiItem
	Block     *funny.Block
	InitLines *funny.Block
	// contains filtered or unexported fields
}

APIRunner the runner

func NewAPIRunnerFromContent

func NewAPIRunnerFromContent(content []byte) *APIRunner

NewAPIRunnerFromContent create a runner from a pica content

func NewAPIRunnerFromFile

func NewAPIRunnerFromFile(filename string, apiNames []string, delay int) *APIRunner

NewAPIRunnerFromFile create a runner from a pica file

func (*APIRunner) DoAPIRequest

func (runner *APIRunner) DoAPIRequest(req *ApiRequest) (*http.Response, error)

DoAPIRequest run the api request

func (*APIRunner) Parse

func (runner *APIRunner) Parse() error

Parse parse pica file

func (*APIRunner) ParseAPIItems

func (runner *APIRunner) ParseAPIItems() error

ParseAPIItems parse ap items from pica code

func (*APIRunner) Run

func (runner *APIRunner) Run() error

Run run the task

func (*APIRunner) RunInitLines

func (runner *APIRunner) RunInitLines()

RunInitLines run the code of initialization

func (*APIRunner) RunSingle

func (runner *APIRunner) RunSingle(item *ApiItem) error

RunSingle run the single api item

type ApiItem

type ApiItem struct {
	Request  *ApiRequest
	Response *ApiResponse
}

type ApiRequest

type ApiRequest struct {
	Headers     http.Header
	Method      string
	Url         string
	Query       Query
	Name        string
	Description string
	Body        []byte
	// contains filtered or unexported fields
}

type ApiResponse

type ApiResponse struct {
	Headers http.Header
	Body    []byte
	Status  int
	// contains filtered or unexported fields
}

type ApiVersionController

type ApiVersionController struct {
	FileName string
	// contains filtered or unexported fields
}

func NewApiVersionController

func NewApiVersionController(filename string) *ApiVersionController

func (*ApiVersionController) Commit

func (v *ApiVersionController) Commit(msg string) (string, error)

func (*ApiVersionController) Diff

func (v *ApiVersionController) Diff(src, dst string) []diffmatchpatch.Diff

func (*ApiVersionController) GetCommits

func (v *ApiVersionController) GetCommits() ([]*object.Commit, error)

func (*ApiVersionController) Notes

func (v *ApiVersionController) Notes() (*VersionNote, error)

type Benchmark

type Benchmark struct {

	//TotalRequests is the total number of requests to be fired.
	TotalRequests uint64
	//BenchDuration is the duration over which all the requests are fired, in milliseconds.
	BenchDuration uint64
	//WaitPerReq is the duration to wait before firing the consecutive request
	WaitPerReq time.Duration
	//ShowProgress is set to true if it should display current stat when the benchmark is running/in progress.
	ShowProgress bool

	//StatReqCount is the number of requests processed after which progress statistics is printed
	StatReqCount uint64
	// contains filtered or unexported fields
}

Benchmark holds all the parameters required to run the benchmark and respective methods

func New

func New() *Benchmark

New returns a new Benchmark pointer with the default values set

func (*Benchmark) Done

func (bA *Benchmark) Done(doneTime time.Duration, err error)

Done does all the operations & calculation required while ending a function call

func (*Benchmark) Final

func (bA *Benchmark) Final()

Final prints all the statistics of the benchmark The input to Final() is the time when you start the benchmark

func (*Benchmark) Init

func (bA *Benchmark) Init()

Init initializes all the fields with their respective values

func (*Benchmark) PrintStat

func (bA *Benchmark) PrintStat()

PrintStat prints the stats available based on the given input params and the global variable values

func (*Benchmark) Run

func (bA *Benchmark) Run(fn func() error)

Run runs the benchmark for the given function

type InitInfo

type InitInfo struct {
	Name        string
	Description string
	Author      string
	Version     string
	BaseUrl     string
}

type MarkdownDocGenerator

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

func NewMarkdownDocGenerator

func NewMarkdownDocGenerator(runner *APIRunner, theme, output string) *MarkdownDocGenerator

func (*MarkdownDocGenerator) Get

func (g *MarkdownDocGenerator) Get() ([]byte, error)

type Output

type Output struct {
	Debug            bool
	DefaultLineCount int
	// contains filtered or unexported fields
}

func NewOutput

func NewOutput(debug bool, writer io.Writer) *Output

func (*Output) CopyRight

func (o *Output) CopyRight()

func (*Output) Echo

func (o *Output) Echo(s string)

func (*Output) EchoRequstIng

func (o *Output) EchoRequstIng(method string, body []byte)

func (*Output) EchoStartRequest

func (o *Output) EchoStartRequest(request *ApiRequest, runner *APIRunner) error

func (*Output) Echoln

func (o *Output) Echoln(s string)

func (*Output) ErrorRequest

func (o *Output) ErrorRequest(err error)

func (*Output) Finished

func (o *Output) Finished(count int, names string)

func (*Output) Headers

func (o *Output) Headers(headers http.Header)

func (*Output) Json

func (o *Output) Json(obj interface{})

func (*Output) L

func (o *Output) L(e string) string

func (*Output) RepeatLine

func (o *Output) RepeatLine(e string, count int) string

func (*Output) RequestBody

func (o *Output) RequestBody(req *http.Request, runner *APIRunner) error

func (*Output) ResponseBody

func (o *Output) ResponseBody(res *http.Response)

func (*Output) W

func (o *Output) W(args ...interface{}) *Output

func (*Output) Wln

func (o *Output) Wln(args ...interface{}) *Output

type PicaContext

type PicaContext struct {
	Name        string
	Description string
	Author      string
	Version     string

	PicaVersion      string
	MaxArrayShowRows int

	ApiItems     []*ApiItem
	Headers      map[string]funny.Value
	VersionNotes *VersionNote
}

func PicaContextFromRunner

func PicaContextFromRunner(runner *APIRunner) *PicaContext

type PostmanScriptsGenerator

type PostmanScriptsGenerator struct {
}

func (*PostmanScriptsGenerator) Generate

func (generator *PostmanScriptsGenerator) Generate(filename string) string

func (*PostmanScriptsGenerator) Name

func (generator *PostmanScriptsGenerator) Name() string

type Project

type Project struct {
	Name      string
	Version   string
	Author    string
	CreatedAt string
	LastRunAt string
	Tasks     map[string][]*Task
}

func NewProject

func NewProject(name, version, author, created, lastRunAt string) *Project

func (*Project) Save

func (p *Project) Save() error

type Query

type Query map[string]interface{}

func CompileURL

func CompileURL(url string, vm *funny.Funny) (string, Query, error)

func NewQuery

func NewQuery(m map[string]interface{}) Query

func ParseQuery

func ParseQuery(queryString string) (Query, error)

func (Query) String

func (query Query) String() (string, error)

type ScriptsGenerator

type ScriptsGenerator interface {
	Name() string
	Generate(filename string) string
}

func NewScriptsGenerator

func NewScriptsGenerator(name string) ScriptsGenerator

type Swagger2ScriptsGenerator

type Swagger2ScriptsGenerator struct {
}

func (*Swagger2ScriptsGenerator) Generate

func (generator *Swagger2ScriptsGenerator) Generate(filename string) string

func (*Swagger2ScriptsGenerator) Name

func (generator *Swagger2ScriptsGenerator) Name() string

type Task

type Task struct {
	Names []string
}

type VersionChange

type VersionChange struct {
	Commit *object.Commit
	Diffs  []diffmatchpatch.Diff
}

type VersionNote

type VersionNote struct {
	Changes []VersionChange
}

Directories

Path Synopsis
cmd
old command
pica command
Package statik contains static assets.
Package statik contains static assets.

Jump to

Keyboard shortcuts

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