mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Update vendor dependencies
This commit is contained in:
parent
34a3fe426b
commit
459bb4531f
747 changed files with 89857 additions and 39711 deletions
25
vendor/google.golang.org/appengine/delay/delay.go
generated
vendored
25
vendor/google.golang.org/appengine/delay/delay.go
generated
vendored
|
@ -9,6 +9,7 @@ user request by using the taskqueue API.
|
|||
To declare a function that may be executed later, call Func
|
||||
in a top-level assignment context, passing it an arbitrary string key
|
||||
and a function whose first argument is of type context.Context.
|
||||
The key is used to look up the function so it can be called later.
|
||||
var laterFunc = delay.Func("key", myFunc)
|
||||
It is also possible to use a function literal.
|
||||
var laterFunc = delay.Func("key", func(c context.Context, x string) {
|
||||
|
@ -73,16 +74,21 @@ const (
|
|||
queue = ""
|
||||
)
|
||||
|
||||
type contextKey int
|
||||
|
||||
var (
|
||||
// registry of all delayed functions
|
||||
funcs = make(map[string]*Function)
|
||||
|
||||
// precomputed types
|
||||
contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
|
||||
errorType = reflect.TypeOf((*error)(nil)).Elem()
|
||||
errorType = reflect.TypeOf((*error)(nil)).Elem()
|
||||
|
||||
// errors
|
||||
errFirstArg = errors.New("first argument must be context.Context")
|
||||
errFirstArg = errors.New("first argument must be context.Context")
|
||||
errOutsideDelayFunc = errors.New("request headers are only available inside a delay.Func")
|
||||
|
||||
// context keys
|
||||
headersContextKey contextKey = 0
|
||||
)
|
||||
|
||||
// Func declares a new Function. The second argument must be a function with a
|
||||
|
@ -105,7 +111,7 @@ func Func(key string, i interface{}) *Function {
|
|||
f.err = errors.New("not a function")
|
||||
return f
|
||||
}
|
||||
if t.NumIn() == 0 || t.In(0) != contextType {
|
||||
if t.NumIn() == 0 || !isContext(t.In(0)) {
|
||||
f.err = errFirstArg
|
||||
return f
|
||||
}
|
||||
|
@ -221,6 +227,15 @@ func (f *Function) Task(args ...interface{}) (*taskqueue.Task, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Request returns the special task-queue HTTP request headers for the current
|
||||
// task queue handler. Returns an error if called from outside a delay.Func.
|
||||
func RequestHeaders(c context.Context) (*taskqueue.RequestHeaders, error) {
|
||||
if ret, ok := c.Value(headersContextKey).(*taskqueue.RequestHeaders); ok {
|
||||
return ret, nil
|
||||
}
|
||||
return nil, errOutsideDelayFunc
|
||||
}
|
||||
|
||||
var taskqueueAdder = taskqueue.Add // for testing
|
||||
|
||||
func init() {
|
||||
|
@ -232,6 +247,8 @@ func init() {
|
|||
func runFunc(c context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
defer req.Body.Close()
|
||||
|
||||
c = context.WithValue(c, headersContextKey, taskqueue.ParseRequestHeaders(req.Header))
|
||||
|
||||
var inv invocation
|
||||
if err := gob.NewDecoder(req.Body).Decode(&inv); err != nil {
|
||||
log.Errorf(c, "delay: failed decoding task payload: %v", err)
|
||||
|
|
23
vendor/google.golang.org/appengine/delay/delay_go17.go
generated
vendored
Normal file
23
vendor/google.golang.org/appengine/delay/delay_go17.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2017 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build go1.7
|
||||
|
||||
package delay
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"reflect"
|
||||
|
||||
netctx "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var (
|
||||
stdContextType = reflect.TypeOf((*stdctx.Context)(nil)).Elem()
|
||||
netContextType = reflect.TypeOf((*netctx.Context)(nil)).Elem()
|
||||
)
|
||||
|
||||
func isContext(t reflect.Type) bool {
|
||||
return t == stdContextType || t == netContextType
|
||||
}
|
55
vendor/google.golang.org/appengine/delay/delay_go17_test.go
generated
vendored
Normal file
55
vendor/google.golang.org/appengine/delay/delay_go17_test.go
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2017 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build go1.7
|
||||
|
||||
package delay
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
stdctx "context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
netctx "golang.org/x/net/context"
|
||||
"google.golang.org/appengine/taskqueue"
|
||||
)
|
||||
|
||||
var (
|
||||
stdCtxRuns = 0
|
||||
stdCtxFunc = Func("stdctx", func(c stdctx.Context) {
|
||||
stdCtxRuns++
|
||||
})
|
||||
)
|
||||
|
||||
func TestStandardContext(t *testing.T) {
|
||||
// Fake out the adding of a task.
|
||||
var task *taskqueue.Task
|
||||
taskqueueAdder = func(_ netctx.Context, tk *taskqueue.Task, queue string) (*taskqueue.Task, error) {
|
||||
if queue != "" {
|
||||
t.Errorf(`Got queue %q, expected ""`, queue)
|
||||
}
|
||||
task = tk
|
||||
return tk, nil
|
||||
}
|
||||
|
||||
c := newFakeContext()
|
||||
stdCtxRuns = 0 // reset state
|
||||
if err := stdCtxFunc.Call(c.ctx); err != nil {
|
||||
t.Fatal("Function.Call:", err)
|
||||
}
|
||||
|
||||
// Simulate the Task Queue service.
|
||||
req, err := http.NewRequest("POST", path, bytes.NewBuffer(task.Payload))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed making http.Request: %v", err)
|
||||
}
|
||||
rw := httptest.NewRecorder()
|
||||
runFunc(c.ctx, rw, req)
|
||||
|
||||
if stdCtxRuns != 1 {
|
||||
t.Errorf("stdCtxRuns: got %d, want 1", stdCtxRuns)
|
||||
}
|
||||
}
|
19
vendor/google.golang.org/appengine/delay/delay_pre17.go
generated
vendored
Normal file
19
vendor/google.golang.org/appengine/delay/delay_pre17.go
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2017 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !go1.7
|
||||
|
||||
package delay
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
|
||||
|
||||
func isContext(t reflect.Type) bool {
|
||||
return t == contextType
|
||||
}
|
53
vendor/google.golang.org/appengine/delay/delay_test.go
generated
vendored
53
vendor/google.golang.org/appengine/delay/delay_test.go
generated
vendored
|
@ -94,6 +94,14 @@ var (
|
|||
dupeWhich = 2
|
||||
}
|
||||
})
|
||||
|
||||
reqFuncRuns = 0
|
||||
reqFuncHeaders *taskqueue.RequestHeaders
|
||||
reqFuncErr error
|
||||
reqFunc = Func("req", func(c context.Context) {
|
||||
reqFuncRuns++
|
||||
reqFuncHeaders, reqFuncErr = RequestHeaders(c)
|
||||
})
|
||||
)
|
||||
|
||||
type fakeContext struct {
|
||||
|
@ -373,3 +381,48 @@ func TestDuplicateFunction(t *testing.T) {
|
|||
t.Errorf("dupeWhich = %d; want 2", dupeWhich)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRequestHeadersFromContext(t *testing.T) {
|
||||
c := newFakeContext()
|
||||
|
||||
// Outside a delay.Func should return an error.
|
||||
headers, err := RequestHeaders(c.ctx)
|
||||
if headers != nil {
|
||||
t.Errorf("RequestHeaders outside Func, got %v, want nil", headers)
|
||||
}
|
||||
if err != errOutsideDelayFunc {
|
||||
t.Errorf("RequestHeaders outside Func err, got %v, want %v", err, errOutsideDelayFunc)
|
||||
}
|
||||
|
||||
// Fake out the adding of a task.
|
||||
var task *taskqueue.Task
|
||||
taskqueueAdder = func(_ context.Context, tk *taskqueue.Task, queue string) (*taskqueue.Task, error) {
|
||||
if queue != "" {
|
||||
t.Errorf(`Got queue %q, expected ""`, queue)
|
||||
}
|
||||
task = tk
|
||||
return tk, nil
|
||||
}
|
||||
|
||||
reqFunc.Call(c.ctx)
|
||||
|
||||
reqFuncRuns, reqFuncHeaders = 0, nil // reset state
|
||||
// Simulate the Task Queue service.
|
||||
req, err := http.NewRequest("POST", path, bytes.NewBuffer(task.Payload))
|
||||
req.Header.Set("x-appengine-taskname", "foobar")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed making http.Request: %v", err)
|
||||
}
|
||||
rw := httptest.NewRecorder()
|
||||
runFunc(c.ctx, rw, req)
|
||||
|
||||
if reqFuncRuns != 1 {
|
||||
t.Errorf("reqFuncRuns: got %d, want 1", reqFuncRuns)
|
||||
}
|
||||
if reqFuncHeaders.TaskName != "foobar" {
|
||||
t.Errorf("reqFuncHeaders.TaskName: got %v, want 'foobar'", reqFuncHeaders.TaskName)
|
||||
}
|
||||
if reqFuncErr != nil {
|
||||
t.Errorf("reqFuncErr: got %v, want nil", reqFuncErr)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue