aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/google.golang.org/appengine/cmd/aefix/ae_test.go
blob: 21f5695b9ae1e52c8e575cb8df6213bdab3af3a0 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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()
}
`,
	},
}