├── .travis.yml ├── go.mod ├── .gitignore ├── hello.qtf ├── httptest ├── exec │ └── plugin │ │ ├── subcmds.go │ │ ├── qbox.go │ │ └── authstub.go └── httptest.go ├── go.sum ├── main.go ├── api └── auth │ └── qbox │ └── qbox_auth.go ├── README.md └── LICENSE /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | script: 3 | - go install -v ./... 4 | - go test -v ./... 5 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/qiniu/qiniutest 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/qiniu/httptest v1.0.3 7 | github.com/qiniu/x v1.10.5 8 | ) 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /hello.qtf: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env qiniutest 2 | 3 | # setUp 4 | # 5 | match $(testenv) `env QiniuTestEnv` 6 | match $(env) `envdecode QiniuTestEnv_$(testenv)` 7 | 8 | host rs.qiniu.com $(env.RSHost) 9 | auth qboxtest `qbox $(env.AK) $(env.SK)` 10 | 11 | echo case setUp 12 | 13 | case testCase1 14 | 15 | post http://rs.qiniu.com/stat/`base64 testqiniu:ecug-2014-place.png` 16 | auth qboxtest 17 | ret 200 18 | echo $(resp) 19 | 20 | case testCase2 21 | 22 | post http://rs.qiniu.com/stat/`base64 testqiniu:ecug-2014-place.png` 23 | auth `qbox $(env.AK) $(env.SK)` 24 | ret 200 25 | 26 | tearDown 27 | 28 | echo case tearDown 29 | 30 | -------------------------------------------------------------------------------- /httptest/exec/plugin/subcmds.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | import ( 4 | "reflect" 5 | 6 | "github.com/qiniu/httptest/exec" 7 | ) 8 | 9 | // --------------------------------------------------------------------------- 10 | 11 | type subContext struct { 12 | ctx exec.IContext 13 | } 14 | 15 | func init() { 16 | 17 | exec.ExternalSub = new(subContext) 18 | } 19 | 20 | func (p *subContext) FindCmd(ctx exec.IContext, cmd string) reflect.Value { 21 | 22 | p.ctx = ctx 23 | v := reflect.ValueOf(p) 24 | return v.MethodByName("Eval_" + cmd) 25 | } 26 | 27 | // --------------------------------------------------------------------------- 28 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/qiniu/dyn v1.3.0 h1:s+xPTeV0H8yikgM4ZMBc7Rrefam8UNI3asBlkaOQg5o= 2 | github.com/qiniu/dyn v1.3.0/go.mod h1:E8oERcm8TtwJiZvkQPbcAh0RL8jO1G0VXJMW3FAWdkk= 3 | github.com/qiniu/httptest v1.0.3 h1:eRw+2DHDk4Irn4z6K1GVVsAHYSM6zSpP6mO5K6CR2jo= 4 | github.com/qiniu/httptest v1.0.3/go.mod h1:NIKzeQ6KD+VyIs27nDQgWdvBbNVr0Xosx8B3anCMxRQ= 5 | github.com/qiniu/x v1.10.5 h1:7V/CYWEmo9axJULvrJN6sMYh2FdY+esN5h8jwDkA4b0= 6 | github.com/qiniu/x v1.10.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs= 7 | gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= 8 | gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= 9 | -------------------------------------------------------------------------------- /httptest/httptest.go: -------------------------------------------------------------------------------- 1 | package httptest 2 | 3 | import ( 4 | "github.com/qiniu/httptest" 5 | "github.com/qiniu/httptest/exec" 6 | 7 | _ "github.com/qiniu/qiniutest/httptest/exec/plugin" 8 | ) 9 | 10 | // --------------------------------------------------------------------------- 11 | 12 | type Context struct { 13 | *httptest.Context 14 | Ectx *exec.Context 15 | } 16 | 17 | func New(t httptest.TestingT) Context { 18 | 19 | ctx := httptest.New(t) 20 | ectx := exec.New() 21 | return Context{ctx, ectx} 22 | } 23 | 24 | func (p Context) Exec(code string) Context { 25 | 26 | p.Context.Exec(p.Ectx, code) 27 | return p 28 | } 29 | 30 | // --------------------------------------------------------------------------- 31 | -------------------------------------------------------------------------------- /httptest/exec/plugin/qbox.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/qiniu/httptest" 7 | "github.com/qiniu/qiniutest/api/auth/qbox" 8 | ) 9 | 10 | // --------------------------------------------------------------------------- 11 | 12 | type authTransportComposer struct { 13 | mac *qbox.Mac 14 | } 15 | 16 | func (p authTransportComposer) Compose(base http.RoundTripper) http.RoundTripper { 17 | return qbox.NewTransport(p.mac, base) 18 | } 19 | 20 | // --------------------------------------------------------------------------- 21 | 22 | type qboxArgs struct { 23 | AK string `arg:"access-key"` 24 | SK string `arg:"secret-key"` 25 | } 26 | 27 | func (p *subContext) Eval_qbox(ctx *httptest.Context, args *qboxArgs) (httptest.TransportComposer, error) { 28 | 29 | mac := &qbox.Mac{ 30 | AccessKey: args.AK, 31 | SecretKey: []byte(args.SK), 32 | } 33 | return authTransportComposer{mac}, nil 34 | } 35 | 36 | // --------------------------------------------------------------------------- 37 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "io/ioutil" 7 | "testing" 8 | 9 | "github.com/qiniu/x/log" 10 | 11 | . "github.com/qiniu/httptest/exec" 12 | _ "github.com/qiniu/qiniutest/httptest/exec/plugin" 13 | ) 14 | 15 | var ( 16 | verbose = flag.Bool("v", false, "verbose") 17 | ) 18 | 19 | // --------------------------------------------------------------------------- 20 | 21 | func allMatch(pat, str string) (bool, error) { 22 | 23 | return true, nil 24 | } 25 | 26 | func allTests(t *testing.T) { 27 | 28 | if *verbose { 29 | log.SetOutputLevel(0) 30 | } 31 | 32 | if flag.NArg() < 1 { 33 | fmt.Println("Usage: qiniutest -v ") 34 | return 35 | } 36 | 37 | filePath := flag.Arg(0) 38 | b, err := ioutil.ReadFile(filePath) 39 | if err != nil { 40 | t.Fatal("ReadFile failed:", err) 41 | return 42 | } 43 | 44 | err = ExecCases(t, string(b)) 45 | if err != nil { 46 | t.Fatal("ExecCases failed:", err) 47 | } 48 | } 49 | 50 | // Usage: qiniutest 51 | // 52 | func main() { 53 | 54 | log.SetFlags(log.Llevel | log.LstdFlags) 55 | tests := []testing.InternalTest{ 56 | {"main", allTests}, 57 | } 58 | testing.Main(allMatch, tests, nil, nil) 59 | } 60 | 61 | // --------------------------------------------------------------------------- 62 | -------------------------------------------------------------------------------- /httptest/exec/plugin/authstub.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | import ( 4 | "encoding/base64" 5 | "encoding/binary" 6 | "net/http" 7 | "strconv" 8 | "syscall" 9 | 10 | "github.com/qiniu/httptest" 11 | ) 12 | 13 | // --------------------------------------------------------------------------- 14 | 15 | type authstubArgs struct { 16 | Uid uint `flag:"uid"` 17 | Utype uint `flag:"utype"` 18 | Sudoer uint `flag:"suid"` 19 | UtypeSu uint `flag:"sut"` 20 | App string `arg:"app,opt"` 21 | } 22 | 23 | func appendUint(form []byte, k string, v uint64) []byte { 24 | 25 | form = append(form, k...) 26 | return strconv.AppendUint(form, v, 10) 27 | } 28 | 29 | func formatAuthstub(user *authstubArgs, appid uint64) string { 30 | 31 | return "QiniuStub " + formatAuthstubToken(user, appid) 32 | } 33 | 34 | func formatAuthstubToken(user *authstubArgs, appid uint64) string { 35 | 36 | form := make([]byte, 0, 128) 37 | form = appendUint(form, "uid=", uint64(user.Uid)) 38 | form = appendUint(form, "&ut=", uint64(user.Utype)) 39 | if appid != 0 { 40 | form = appendUint(form, "&app=", uint64(appid)) 41 | } 42 | if user.Sudoer != 0 { 43 | form = appendUint(form, "&suid=", uint64(user.Sudoer)) 44 | if user.UtypeSu != 0 { 45 | form = appendUint(form, "&sut=", uint64(user.UtypeSu)) 46 | } 47 | } 48 | return string(form) 49 | } 50 | 51 | // --------------------------------------------------------------------------- 52 | 53 | type authstubTransport struct { 54 | auth string 55 | Transport http.RoundTripper 56 | } 57 | 58 | func (t *authstubTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) { 59 | 60 | req.Header.Set("Authorization", t.auth) 61 | return t.Transport.RoundTrip(req) 62 | } 63 | 64 | func (t *authstubTransport) NestedObject() interface{} { 65 | 66 | return t.Transport 67 | } 68 | 69 | func authstubNewTransport( 70 | user *authstubArgs, appid uint64, transport http.RoundTripper) *authstubTransport { 71 | 72 | if transport == nil { 73 | transport = http.DefaultTransport 74 | } 75 | return &authstubTransport{formatAuthstub(user, appid), transport} 76 | } 77 | 78 | // --------------------------------------------------------------------------- 79 | 80 | type authstubTransportComposer struct { 81 | args *authstubArgs 82 | ctx *httptest.Context 83 | } 84 | 85 | func toAppId(app string) (appId uint64, err error) { 86 | 87 | b, err := base64.URLEncoding.DecodeString(app) 88 | if err != nil { 89 | return 90 | } 91 | if len(b) != 12 { 92 | return 0, syscall.EINVAL 93 | } 94 | return binary.LittleEndian.Uint64(b[4:]), nil 95 | } 96 | 97 | func (p *authstubTransportComposer) Compose(base http.RoundTripper) http.RoundTripper { 98 | 99 | var appid uint64 100 | var err error 101 | 102 | if p.args.App != "" { 103 | appid, err = strconv.ParseUint(p.args.App, 10, 64) 104 | if err != nil { 105 | appid, err = toAppId(p.args.App) 106 | if err != nil { 107 | p.ctx.Fatal("Parse arg `app` failed:", err) 108 | } 109 | } 110 | } 111 | return authstubNewTransport(p.args, appid, base) 112 | } 113 | 114 | func (p *subContext) Eval_authstub( 115 | ctx *httptest.Context, args *authstubArgs) (httptest.TransportComposer, error) { 116 | 117 | return &authstubTransportComposer{args, ctx}, nil 118 | } 119 | 120 | // --------------------------------------------------------------------------- 121 | -------------------------------------------------------------------------------- /api/auth/qbox/qbox_auth.go: -------------------------------------------------------------------------------- 1 | package qbox 2 | 3 | import ( 4 | "crypto/hmac" 5 | "crypto/sha1" 6 | "encoding/base64" 7 | "io" 8 | "net/http" 9 | 10 | "github.com/qiniu/x/bytes/seekable" 11 | ) 12 | 13 | // ---------------------------------------------------------- 14 | 15 | type Mac struct { 16 | AccessKey string 17 | SecretKey []byte 18 | } 19 | 20 | func NewMac(accessKey, secretKey string) (mac *Mac) { 21 | 22 | return &Mac{accessKey, []byte(secretKey)} 23 | } 24 | 25 | func (mac *Mac) Sign(data []byte) (token string) { 26 | 27 | h := hmac.New(sha1.New, mac.SecretKey) 28 | h.Write(data) 29 | 30 | sign := base64.URLEncoding.EncodeToString(h.Sum(nil)) 31 | return mac.AccessKey + ":" + sign[:27] 32 | } 33 | 34 | func (mac *Mac) SignWithData(b []byte) (token string) { 35 | 36 | blen := base64.URLEncoding.EncodedLen(len(b)) 37 | 38 | key := mac.AccessKey 39 | nkey := len(key) 40 | ret := make([]byte, nkey+30+blen) 41 | 42 | base64.URLEncoding.Encode(ret[nkey+30:], b) 43 | 44 | h := hmac.New(sha1.New, mac.SecretKey) 45 | h.Write(ret[nkey+30:]) 46 | digest := h.Sum(nil) 47 | 48 | copy(ret, key) 49 | ret[nkey] = ':' 50 | base64.URLEncoding.Encode(ret[nkey+1:], digest) 51 | ret[nkey+29] = ':' 52 | 53 | return string(ret) 54 | } 55 | 56 | func (mac *Mac) SignRequest(req *http.Request, incbody bool) (token string, err error) { 57 | 58 | h := hmac.New(sha1.New, mac.SecretKey) 59 | 60 | u := req.URL 61 | data := u.Path 62 | if u.RawQuery != "" { 63 | data += "?" + u.RawQuery 64 | } 65 | io.WriteString(h, data+"\n") 66 | 67 | if incbody { 68 | s2, err2 := seekable.New(req) 69 | if err2 != nil { 70 | return "", err2 71 | } 72 | h.Write(s2.Bytes()) 73 | } 74 | 75 | sign := base64.URLEncoding.EncodeToString(h.Sum(nil)) 76 | token = mac.AccessKey + ":" + sign 77 | return 78 | } 79 | 80 | func (mac *Mac) VerifyCallback(req *http.Request) (bool, error) { 81 | 82 | auth := req.Header.Get("Authorization") 83 | if auth == "" { 84 | return false, nil 85 | } 86 | 87 | token, err := mac.SignRequest(req, true) 88 | if err != nil { 89 | return false, err 90 | } 91 | 92 | return auth == "QBox "+token, nil 93 | } 94 | 95 | // --------------------------------------------------------------------------------------- 96 | 97 | type Transport struct { 98 | mac Mac 99 | Transport http.RoundTripper 100 | } 101 | 102 | func incBody(req *http.Request) bool { 103 | 104 | if req.Body == nil { 105 | return false 106 | } 107 | if ct, ok := req.Header["Content-Type"]; ok { 108 | switch ct[0] { 109 | case "application/x-www-form-urlencoded": 110 | return true 111 | } 112 | } 113 | return false 114 | } 115 | 116 | func (t *Transport) NestedObject() interface{} { 117 | 118 | return t.Transport 119 | } 120 | 121 | func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) { 122 | 123 | token, err := t.mac.SignRequest(req, incBody(req)) 124 | if err != nil { 125 | return 126 | } 127 | req.Header.Set("Authorization", "QBox "+token) 128 | return t.Transport.RoundTrip(req) 129 | } 130 | 131 | func NewTransport(mac *Mac, transport http.RoundTripper) *Transport { 132 | 133 | if transport == nil { 134 | transport = http.DefaultTransport 135 | } 136 | t := &Transport{mac: *mac, Transport: transport} 137 | return t 138 | } 139 | 140 | func NewClient(mac *Mac, transport http.RoundTripper) *http.Client { 141 | 142 | t := NewTransport(mac, transport) 143 | return &http.Client{Transport: t} 144 | } 145 | 146 | // --------------------------------------------------------------------------------------- 147 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | qiniutest manual 2 | ========================= 3 | 4 | [![LICENSE](https://img.shields.io/github/license/qiniu/qiniutest.svg)](https://github.com/qiniu/qiniutest/blob/master/LICENSE) 5 | [![Build Status](https://travis-ci.org/qiniu/qiniutest.svg?branch=master)](https://travis-ci.org/qiniu/qiniutest) [![Go Report Card](https://goreportcard.com/badge/github.com/qiniu/qiniutest)](https://goreportcard.com/report/github.com/qiniu/qiniutest) [![GitHub release](https://img.shields.io/github/v/tag/qiniu/qiniutest.svg?label=release)](https://github.com/qiniu/qiniutest/releases) 6 | [![GoDoc](https://img.shields.io/badge/Godoc-reference-blue.svg)](https://godoc.org/github.com/qiniu/qiniutest) 7 | 8 | [![Qiniu Logo](http://open.qiniudn.com/logo.png)](http://www.qiniu.com/) 9 | 10 | Deprecated: This project is moved to [github.com/goplus/yap/ytest](https://github.com/goplus/yap/tree/main/ytest) (It's no longer a DSL, but a Go+ classfile, which makes it even more powerful). 11 | 12 | # 下载 13 | 14 | ``` 15 | go get -u github.com/qiniu/qiniutest 16 | ``` 17 | 18 | # 基础原理 19 | 20 | * [httptest/README.md](https://github.com/qiniu/httptest) 21 | 22 | # 命令行 23 | 24 | ```bash 25 | qiniutest -v 26 | ``` 27 | 28 | 由 qiniutest 程序解释并执行 QTF 文件描述的测试脚本。指定 `-v` 参数表示 verbose,会获得更多的调试信息输出。 29 | 30 | 如果我们在 QTF 文件开头加上这样一行: 31 | 32 | ```bash 33 | #!/usr/bin/env qiniutest 34 | ``` 35 | 36 | 并把 `` 文件设置为可执行: 37 | 38 | ```bash 39 | chmod +x 40 | ``` 41 | 42 | 如此就可以直接运行它: 43 | 44 | ```bash 45 | ./ 46 | ``` 47 | 48 | # QTF 语言手册 49 | 50 | ## 命令 51 | 52 | ### match 53 | 54 | 匹配两个object。语法: 55 | 56 | ```bash 57 | match 58 | ``` 59 | 60 | 关于 match 的详细解释,参见: 61 | 62 | * [httptest/README.md](https://github.com/qiniu/httptest) 63 | 64 | ### host 65 | 66 | 样例1:使用环境变量来选择 stage 还是 product 67 | 68 | ```bash 69 | match $(testenv) `env QiniuTestEnv` 70 | match $(env) `envdecode QiniuTestEnv_$(testenv)` 71 | 72 | host rs.qiniu.com $(env.RSHost) 73 | ``` 74 | 75 | 这样,测试人员只需要配置环境: 76 | 77 | ```bash 78 | export QiniuTestEnv_stage='{ 79 | "RSHost": "192.168.1.10:9999", 80 | "AK": "...", 81 | "SK": "..." 82 | }' 83 | 84 | export QiniuTestEnv_product='{ 85 | "RSHost": "rs.qiniu.com", 86 | "AK": "...", 87 | "SK": "..." 88 | }' 89 | ``` 90 | 91 | 然后: 92 | 93 | ```bash 94 | QiniuTestEnv=stage qiniutest # 测试stage环境 95 | QiniuTestEnv=product qiniutest # 测试product环境 96 | ``` 97 | 98 | ### auth 99 | 100 | 定义 auth 信息: 101 | 102 | ```bash 103 | auth 104 | ``` 105 | 106 | 在某次请求时引用 auth: 107 | 108 | ```bash 109 | # 这里的 可以是之前已经定义好的 ,也可以直接是某个 110 | auth 111 | ``` 112 | 113 | auth 信息通常用 AccessKey/SecretKey,或者 Username/Password,都是很敏感的信息,一般通过 env 传入,避免随着脚本入库。 114 | 115 | 样例1: 116 | 117 | ```bash 118 | match $(testenv) `env QiniuTestEnv` 119 | match $(env) `envdecode QiniuTestEnv_$(testenv)` 120 | 121 | host rs.qiniu.com $(env.RSHost) 122 | auth qboxtest `qbox $(env.AK) $(env.SK)` 123 | 124 | post http://rs.qiniu.com/stat/`base64 testqiniu:ecug-2014-place.png` 125 | auth qboxtest 126 | ret 200 127 | echo $(resp) 128 | ``` 129 | 130 | 它等价于: 131 | 132 | ```bash 133 | match $(testenv) `env QiniuTestEnv` 134 | match $(env) `envdecode QiniuTestEnv_$(testenv)` 135 | 136 | host rs.qiniu.com $(env.RSHost) 137 | 138 | post http://rs.qiniu.com/stat/`base64 testqiniu:ecug-2014-place.png` 139 | auth `qbox $(env.AK) $(env.SK)` 140 | ret 200 141 | echo $(resp) 142 | ``` 143 | 144 | ### echo/println 145 | 146 | echo/println功能相同,都用于调试、打印信息。语法: 147 | 148 | ```bash 149 | echo ... 150 | ``` 151 | 152 | ### req/post/get/delete/put 153 | 154 | req 发起一个请求: 155 | 156 | ```bash 157 | req 158 | ``` 159 | 160 | 而 post/get/delete/put 是 `http-method` 分别为 POST/GET/DELETE/PUT 时的简写。如: 161 | 162 | ```bash 163 | post 164 | ``` 165 | 166 | ### header 167 | 168 | 用于指定请求包或返回包的某个头部信息。语法: 169 | 170 | ```bash 171 | header ... 172 | ``` 173 | 174 | 需要注意的是,在返回包匹配时,语句: 175 | 176 | ```bash 177 | header Content-Type $(mime) 178 | ``` 179 | 180 | 如果 $(resp.header.Content-Type) 是 ["application/json"],那么得到的 $(mime) 并不是 ["application/json"],而是 "application/json"。如果希望是 ["application/json"],则应该这样写: 181 | 182 | ```bash 183 | match $(mime) $(resp.header.Content-Type) 184 | ``` 185 | 186 | ### body/json/form/text/binary 187 | 188 | body 用于指定请求包或返回包的正文内容。语法: 189 | 190 | ```bash 191 | body 192 | ``` 193 | 194 | 其中 `` 可以是 "application/json"、"application/text" 这样的全称,也可以简写为 "json"、"form"、"text"。 195 | 196 | 而 json/form 指令是 `` 为 json/form 时的简写。如: 197 | 198 | ```bash 199 | json 200 | ``` 201 | 202 | 等价于: 203 | 204 | ```bash 205 | body json 206 | ``` 207 | 208 | 而 binary 指令是 `` 为 "application/octet-stream" 的简写。如: 209 | 210 | ```bash 211 | binary 212 | ``` 213 | 214 | 等价于: 215 | 216 | ```bash 217 | body application/octet-stream 218 | ``` 219 | 220 | ### ret 221 | 222 | ret 用来获得返回包。语法: 223 | 224 | ```bash 225 | ret [] 226 | ``` 227 | 228 | 在指定了 `` 时,会要求返回的 $(resp.code) 与该 status code 相符,否则测试失败。语句: 229 | 230 | ```bash 231 | ret 232 | ``` 233 | 234 | 等价于: 235 | 236 | ```bash 237 | ret 238 | match $(resp.code) 239 | ``` 240 | 241 | ### clear 242 | 243 | clear 用来清除已经绑定的变量。语法: 244 | 245 | ```bash 246 | clear ... 247 | ``` 248 | 249 | ### let 250 | 251 | let 用于变量赋值,和主流命令式编程语言的 `=` 最为接近。例如: 252 | 253 | ```bash 254 | let $(var-name) 255 | ``` 256 | 257 | 等价于: 258 | 259 | ```bash 260 | clear var-name 261 | match $(var-name) 262 | ``` 263 | 264 | ### equal/equalSet 265 | 266 | equal 要求两个 object 的内容精确相等: 267 | 268 | ```bash 269 | equal 270 | ``` 271 | 272 | equalSet 要求两个 object 都是 array,并且把两个 array 看作集合,要求两个集合精确相等: 273 | 274 | ```bash 275 | equalSet 276 | ``` 277 | 278 | 也就是两个 array 的元素排序后应该精确相同。 279 | 280 | ## 子命令 281 | 282 | ### base64 283 | 284 | ```bash 285 | base64 -d -std 286 | ``` 287 | 288 | 对一段文本进行 base64 编码(encode)。如果指定了 `-d` 参数则为解码(decode)。如果指定了 `-std` 则使用 base64.StdEncoding(默认使用的是 UrlSafe 的 base64.URLEncoding)进行编解码。 289 | 290 | ### env 291 | 292 | ```bash 293 | env 294 | ``` 295 | 296 | 取得环境变量对应的文本。 297 | 298 | ### decode 299 | 300 | ```bash 301 | decode 302 | ``` 303 | 304 | 对一段 json 文本进行解码(decode)。 305 | 306 | ### envdecode 307 | 308 | ```bash 309 | envdecode 310 | ``` 311 | 312 | 取得一个环境变量对应的文本,并且进行解码(json decode)。等价于: 313 | 314 | ```bash 315 | match $(__auto_var1) `env ` 316 | decode $(__auto_var1) 317 | ``` 318 | 319 | ### qbox 320 | 321 | ```bash 322 | qbox 323 | ``` 324 | 325 | 返回由七牛云存储 qbox 规范定义的 `auth interface`,可被 `auth` 命令使用。如: 326 | 327 | ```bash 328 | auth `qbox ` 329 | ``` 330 | 331 | ### authstub 332 | 333 | ```bash 334 | authstub -uid -utype 335 | ``` 336 | 337 | 返回由七牛内部定义的 mock authorization 授权的 `auth interface`,可被 `auth` 命令使用。如: 338 | 339 | ```bash 340 | auth `authstub -uid 1 -utype 4` 341 | ``` 342 | 343 | 这样就模拟了一个 uid 为 1 的标准用户。 344 | 345 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------