123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // 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()
- }
- `,
- },
- }
|