github.com/psiphon-labs/goarista@v0.0.0-20160825065156-d002785f4c67/key/composite_test.go (about) 1 // Copyright (C) 2016 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 package key_test 6 7 import ( 8 "testing" 9 10 . "github.com/aristanetworks/goarista/key" 11 "github.com/aristanetworks/goarista/test" 12 ) 13 14 type unhashable struct { 15 f func() 16 u uintptr 17 } 18 19 func TestBadComposite(t *testing.T) { 20 test.ShouldPanicWith(t, "use of unhashable type in a map", func() { 21 m := map[interface{}]struct{}{ 22 unhashable{func() {}, 0x42}: struct{}{}, 23 } 24 // Use Key here to make sure init() is called. 25 if _, ok := m[New("foo")]; ok { 26 t.Fatal("WTF") 27 } 28 }) 29 test.ShouldPanicWith(t, "use of uncomparable type on the lhs of ==", func() { 30 var a interface{} 31 var b interface{} 32 a = unhashable{func() {}, 0x42} 33 b = unhashable{func() {}, 0x42} 34 // Use Key here to make sure init() is called. 35 if a == b { 36 t.Fatal("WTF") 37 } 38 }) 39 }