-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathappwrap_test.go
50 lines (39 loc) · 1.15 KB
/
appwrap_test.go
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
package appwrap
import (
"os"
"reflect"
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type AppengineInterfacesTest struct{}
var _ = Suite(&AppengineInterfacesTest{})
func (t *AppengineInterfacesTest) SetUpSuite(c *C) {
os.Setenv("GOOGLE_CLOUD_PROJECT", "theapp")
os.Setenv("GAE_SERVICE", "theservice")
os.Setenv("GAE_VERSION", "theversion")
}
func sameMemory(one, two interface{}) bool {
valOne, valTwo := reflect.ValueOf(one), reflect.ValueOf(two)
if valOne.Kind() != valTwo.Kind() {
return false
}
switch valOne.Kind() {
case reflect.Slice:
return valOne.Pointer() == valTwo.Pointer() && valOne.Cap() == valTwo.Cap()
case reflect.Map:
return valOne.Pointer() == valTwo.Pointer()
default:
panic("unsupported type")
}
}
func (s *AppengineInterfacesTest) TestSameMemory(c *C) {
thing := make(map[string]interface{}, 0)
c.Assert(sameMemory(thing, thing), IsTrue)
thingTwo := make(map[string]interface{}, 0)
c.Assert(sameMemory(thing, thingTwo), IsFalse)
slice := make([]string, 0, 10)
c.Assert(sameMemory(slice, slice), IsTrue)
sliceTwo := make([]string, 0, 10)
c.Assert(sameMemory(slice, sliceTwo), IsFalse)
}