/usr/share/gocode/src/google.golang.org/appengine/taskqueue/taskqueue_test.go is in golang-google-appengine-dev 0.0~git20150606-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | // Copyright 2014 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.
package taskqueue
import (
"errors"
"fmt"
"reflect"
"testing"
"google.golang.org/appengine"
"google.golang.org/appengine/internal"
"google.golang.org/appengine/internal/aetesting"
pb "google.golang.org/appengine/internal/taskqueue"
)
func TestAddErrors(t *testing.T) {
var tests = []struct {
err, want error
sameErr bool // if true, should return err exactly
}{
{
err: &internal.APIError{
Service: "taskqueue",
Code: int32(pb.TaskQueueServiceError_TASK_ALREADY_EXISTS),
},
want: ErrTaskAlreadyAdded,
},
{
err: &internal.APIError{
Service: "taskqueue",
Code: int32(pb.TaskQueueServiceError_TOMBSTONED_TASK),
},
want: ErrTaskAlreadyAdded,
},
{
err: &internal.APIError{
Service: "taskqueue",
Code: int32(pb.TaskQueueServiceError_UNKNOWN_QUEUE),
},
want: errors.New("not used"),
sameErr: true,
},
}
for _, tc := range tests {
c := aetesting.FakeSingleContext(t, "taskqueue", "Add", func(req *pb.TaskQueueAddRequest, res *pb.TaskQueueAddResponse) error {
// don't fill in any of the response
return tc.err
})
task := &Task{Path: "/worker", Method: "PULL"}
_, err := Add(c, task, "a-queue")
want := tc.want
if tc.sameErr {
want = tc.err
}
if err != want {
t.Errorf("Add with tc.err = %v, got %#v, want = %#v", tc.err, err, want)
}
}
}
func TestAddMulti(t *testing.T) {
c := aetesting.FakeSingleContext(t, "taskqueue", "BulkAdd", func(req *pb.TaskQueueBulkAddRequest, res *pb.TaskQueueBulkAddResponse) error {
res.Taskresult = []*pb.TaskQueueBulkAddResponse_TaskResult{
{
Result: pb.TaskQueueServiceError_OK.Enum(),
},
{
Result: pb.TaskQueueServiceError_TASK_ALREADY_EXISTS.Enum(),
},
{
Result: pb.TaskQueueServiceError_TOMBSTONED_TASK.Enum(),
},
{
Result: pb.TaskQueueServiceError_INTERNAL_ERROR.Enum(),
},
}
return nil
})
tasks := []*Task{
{Path: "/worker", Method: "PULL"},
{Path: "/worker", Method: "PULL"},
{Path: "/worker", Method: "PULL"},
{Path: "/worker", Method: "PULL"},
}
r, err := AddMulti(c, tasks, "a-queue")
if len(r) != len(tasks) {
t.Fatalf("AddMulti returned %d tasks, want %d", len(r), len(tasks))
}
want := appengine.MultiError{
nil,
ErrTaskAlreadyAdded,
ErrTaskAlreadyAdded,
&internal.APIError{
Service: "taskqueue",
Code: int32(pb.TaskQueueServiceError_INTERNAL_ERROR),
},
}
if !reflect.DeepEqual(err, want) {
t.Errorf("AddMulti got %v, wanted %v", err, want)
}
}
func TestAddWithEmptyPath(t *testing.T) {
c := aetesting.FakeSingleContext(t, "taskqueue", "Add", func(req *pb.TaskQueueAddRequest, res *pb.TaskQueueAddResponse) error {
if got, want := string(req.Url), "/_ah/queue/a-queue"; got != want {
return fmt.Errorf("unexpected Url, got %q want %q", got, want)
}
return nil
})
task := &Task{}
_, err := Add(c, task, "a-queue")
if err != nil {
t.Fatalf("Add: %v", err)
}
}
|