remove stray struct equality check

This check was moved to qtls.
This commit is contained in:
Marten Seemann
2021-03-09 16:17:10 +08:00
parent 506281b904
commit 1113892489
2 changed files with 0 additions and 79 deletions

View File

@@ -1,19 +0,0 @@
package qtls
import "reflect"
func structsEqual(a, b interface{}) bool {
sa := reflect.ValueOf(a).Elem()
sb := reflect.ValueOf(b).Elem()
if sa.NumField() != sb.NumField() {
return false
}
for i := 0; i < sa.NumField(); i++ {
fa := sa.Type().Field(i)
fb := sb.Type().Field(i)
if !reflect.DeepEqual(fa.Index, fb.Index) || fa.Name != fb.Name || fa.Anonymous != fb.Anonymous || fa.Offset != fb.Offset || !reflect.DeepEqual(fa.Type, fb.Type) {
return false
}
}
return true
}

View File

@@ -1,60 +0,0 @@
package qtls
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type target struct {
Name string
Version string
callback func(label string, length int) error
}
type renamedField struct {
NewName string
Version string
callback func(label string, length int) error
}
type renamedPrivateField struct {
Name string
Version string
cb func(label string, length int) error
}
type additionalField struct {
Name string
Version string
callback func(label string, length int) error
secret []byte
}
type interchangedFields struct {
Version string
Name string
callback func(label string, length int) error
}
type renamedCallbackFunctionParams struct { // should be equivalent
Name string
Version string
callback func(newLabel string, length int) error
}
var _ = Describe("Unsafe checks", func() {
It("detects if an unsafe conversion is safe", func() {
Expect(structsEqual(&target{}, &target{})).To(BeTrue())
Expect(structsEqual(&target{}, &renamedField{})).To(BeFalse())
Expect(structsEqual(&target{}, &renamedPrivateField{})).To(BeFalse())
Expect(structsEqual(&target{}, &additionalField{})).To(BeFalse())
Expect(structsEqual(&target{}, &interchangedFields{})).To(BeFalse())
Expect(structsEqual(&target{}, &renamedCallbackFunctionParams{})).To(BeTrue())
})
})