summaryrefslogtreecommitdiffstats
path: root/vendor/google.golang.org/appengine/cmd/aefix/ae_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/appengine/cmd/aefix/ae_test.go')
-rw-r--r--vendor/google.golang.org/appengine/cmd/aefix/ae_test.go144
1 files changed, 144 insertions, 0 deletions
diff --git a/vendor/google.golang.org/appengine/cmd/aefix/ae_test.go b/vendor/google.golang.org/appengine/cmd/aefix/ae_test.go
new file mode 100644
index 000000000..21f5695b9
--- /dev/null
+++ b/vendor/google.golang.org/appengine/cmd/aefix/ae_test.go
@@ -0,0 +1,144 @@
+// Copyright 2016 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 main
+
+func init() {
+ addTestCases(aeTests, nil)
+}
+
+var aeTests = []testCase{
+ // Collection of fixes:
+ // - imports
+ // - appengine.Timeout -> context.WithTimeout
+ // - add ctx arg to appengine.Datacenter
+ // - logging API
+ {
+ Name: "ae.0",
+ In: `package foo
+
+import (
+ "net/http"
+ "time"
+
+ "appengine"
+ "appengine/datastore"
+)
+
+func f(w http.ResponseWriter, r *http.Request) {
+ c := appengine.NewContext(r)
+
+ c = appengine.Timeout(c, 5*time.Second)
+ err := datastore.ErrNoSuchEntity
+ c.Errorf("Something interesting happened: %v", err)
+ _ = appengine.Datacenter()
+}
+`,
+ Out: `package foo
+
+import (
+ "net/http"
+ "time"
+
+ "golang.org/x/net/context"
+ "google.golang.org/appengine"
+ "google.golang.org/appengine/datastore"
+ "google.golang.org/appengine/log"
+)
+
+func f(w http.ResponseWriter, r *http.Request) {
+ c := appengine.NewContext(r)
+
+ c, _ = context.WithTimeout(c, 5*time.Second)
+ err := datastore.ErrNoSuchEntity
+ log.Errorf(c, "Something interesting happened: %v", err)
+ _ = appengine.Datacenter(c)
+}
+`,
+ },
+
+ // Updating a function that takes an appengine.Context arg.
+ {
+ Name: "ae.1",
+ In: `package foo
+
+import (
+ "appengine"
+)
+
+func LogSomething(c2 appengine.Context) {
+ c2.Warningf("Stand back! I'm going to try science!")
+}
+`,
+ Out: `package foo
+
+import (
+ "golang.org/x/net/context"
+ "google.golang.org/appengine/log"
+)
+
+func LogSomething(c2 context.Context) {
+ log.Warningf(c2, "Stand back! I'm going to try science!")
+}
+`,
+ },
+
+ // Less widely used API changes:
+ // - drop maxTasks arg to taskqueue.QueueStats
+ {
+ Name: "ae.2",
+ In: `package foo
+
+import (
+ "appengine"
+ "appengine/taskqueue"
+)
+
+func f(ctx appengine.Context) {
+ stats, err := taskqueue.QueueStats(ctx, []string{"one", "two"}, 0)
+}
+`,
+ Out: `package foo
+
+import (
+ "golang.org/x/net/context"
+ "google.golang.org/appengine/taskqueue"
+)
+
+func f(ctx context.Context) {
+ stats, err := taskqueue.QueueStats(ctx, []string{"one", "two"})
+}
+`,
+ },
+
+ // Check that the main "appengine" import will not be dropped
+ // if an appengine.Context -> context.Context change happens
+ // but the appengine package is still referenced.
+ {
+ Name: "ae.3",
+ In: `package foo
+
+import (
+ "appengine"
+ "io"
+)
+
+func f(ctx appengine.Context, w io.Writer) {
+ _ = appengine.IsDevAppServer()
+}
+`,
+ Out: `package foo
+
+import (
+ "golang.org/x/net/context"
+ "google.golang.org/appengine"
+ "io"
+)
+
+func f(ctx context.Context, w io.Writer) {
+ _ = appengine.IsDevAppServer()
+}
+`,
+ },
+}