summaryrefslogtreecommitdiff
path: root/vendor
diff options
context:
space:
mode:
authorzhengxinwei <zhengxinwei@huawei.com>2023-07-22 14:55:12 +0800
committerzhengxinwei <zhengxinwei@huawei.com>2023-10-07 09:46:55 +0800
commitaa3ba72d383d125ec3d84783a539d5b0d4c5c62c (patch)
treecac86dfb50fb6608e1b77c2e722d0661593fdabf /vendor
parentMerge pull request #5040 from Onion-of-dreamed/fix/without-mqtt-tag (diff)
downloadkubeedge-aa3ba72d383d125ec3d84783a539d5b0d4c5c62c.tar.gz
metaserver support pass through API, open /version path
Signed-off-by: zhengxinwei <zhengxinwei@huawei.com>
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/agiledragon/gomonkey/LICENSE21
-rw-r--r--vendor/github.com/agiledragon/gomonkey/README.md37
-rw-r--r--vendor/github.com/agiledragon/gomonkey/jmp_amd64.go18
-rw-r--r--vendor/github.com/agiledragon/gomonkey/modify_binary_darwin.go19
-rw-r--r--vendor/github.com/agiledragon/gomonkey/modify_binary_linux.go19
-rw-r--r--vendor/github.com/agiledragon/gomonkey/modify_binary_windows.go25
-rw-r--r--vendor/github.com/agiledragon/gomonkey/patch.go232
-rw-r--r--vendor/modules.txt3
8 files changed, 374 insertions, 0 deletions
diff --git a/vendor/github.com/agiledragon/gomonkey/LICENSE b/vendor/github.com/agiledragon/gomonkey/LICENSE
new file mode 100644
index 000000000..d75dc90e6
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Zhang Xiaolong
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/agiledragon/gomonkey/README.md b/vendor/github.com/agiledragon/gomonkey/README.md
new file mode 100644
index 000000000..04d9e73c0
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/README.md
@@ -0,0 +1,37 @@
+# gomonkey
+
+gomonkey is a library to make monkey patching in unit tests easy.
+
+## Features
+
++ support a patch for a function
++ support a patch for a member method
++ support a patch for a interface
++ support a patch for a function variable
++ support a patch for a global variable
++ support patches of a specified sequence for a function
++ support patches of a specified sequence for a member method
++ support patches of a specified sequence for a interface
++ support patches of a specified sequence for a function variable
+
+## Notes
++ gomonkey fails to patch a function or a member method if inlining is enabled, please running your tests with inlining disabled by adding the command line argument that is `-gcflags=-l`(below go1.10) or `-gcflags=all=-l`(go1.10 and above).
++ gomonkey should work on any amd64 system.
++ A panic may happen when a goroutine is patching a function or a member method that is visited by another goroutine at the same time. That is to say, gomonkey is not threadsafe.
++ go1.6 version of the reflection mechanism supports the query of private member methods, but go1.7 and above does not support it. However, all versions of the reflection mechanism support the query of private functions, so gomonkey will trigger a `panic` for only patching a private member method when go1.7 and above is used.
+
+
+## Supported Platform:
+
+- MAC OS X amd64
+- Linux amd64
+- Windows amd64
+
+## Installation
+```go
+$ go get github.com/agiledragon/gomonkey
+```
+## Using gomonkey
+
+Please refer to the test cases as idioms, very complete and detailed.
+
diff --git a/vendor/github.com/agiledragon/gomonkey/jmp_amd64.go b/vendor/github.com/agiledragon/gomonkey/jmp_amd64.go
new file mode 100644
index 000000000..02c1c42c7
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/jmp_amd64.go
@@ -0,0 +1,18 @@
+package gomonkey
+
+func buildJmpDirective(double uintptr) []byte {
+ d0 := byte(double)
+ d1 := byte(double >> 8)
+ d2 := byte(double >> 16)
+ d3 := byte(double >> 24)
+ d4 := byte(double >> 32)
+ d5 := byte(double >> 40)
+ d6 := byte(double >> 48)
+ d7 := byte(double >> 56)
+
+ return []byte{
+ 0x48, 0xBA, d0, d1, d2, d3, d4, d5, d6, d7, // MOV rdx, double
+ 0xFF, 0x22, // JMP [rdx]
+ }
+}
+
diff --git a/vendor/github.com/agiledragon/gomonkey/modify_binary_darwin.go b/vendor/github.com/agiledragon/gomonkey/modify_binary_darwin.go
new file mode 100644
index 000000000..458aa3381
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/modify_binary_darwin.go
@@ -0,0 +1,19 @@
+package gomonkey
+
+import "syscall"
+
+func modifyBinary(target uintptr, bytes []byte) {
+ function := entryAddress(target, len(bytes))
+
+ page := entryAddress(pageStart(target), syscall.Getpagesize())
+ err := syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC)
+ if err != nil {
+ panic(err)
+ }
+ copy(function, bytes)
+
+ err = syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_EXEC)
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/vendor/github.com/agiledragon/gomonkey/modify_binary_linux.go b/vendor/github.com/agiledragon/gomonkey/modify_binary_linux.go
new file mode 100644
index 000000000..458aa3381
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/modify_binary_linux.go
@@ -0,0 +1,19 @@
+package gomonkey
+
+import "syscall"
+
+func modifyBinary(target uintptr, bytes []byte) {
+ function := entryAddress(target, len(bytes))
+
+ page := entryAddress(pageStart(target), syscall.Getpagesize())
+ err := syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC)
+ if err != nil {
+ panic(err)
+ }
+ copy(function, bytes)
+
+ err = syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_EXEC)
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/vendor/github.com/agiledragon/gomonkey/modify_binary_windows.go b/vendor/github.com/agiledragon/gomonkey/modify_binary_windows.go
new file mode 100644
index 000000000..ef0dbc756
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/modify_binary_windows.go
@@ -0,0 +1,25 @@
+package gomonkey
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+func modifyBinary(target uintptr, bytes []byte) {
+ function := entryAddress(target, len(bytes))
+
+ proc := syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect")
+ const PROT_READ_WRITE = 0x40
+ var old uint32
+ result, _, _ := proc.Call(target, uintptr(len(bytes)), uintptr(PROT_READ_WRITE), uintptr(unsafe.Pointer(&old)))
+ if result == 0 {
+ panic(result)
+ }
+ copy(function, bytes)
+
+ var ignore uint32
+ result, _, _ = proc.Call(target, uintptr(len(bytes)), uintptr(old), uintptr(unsafe.Pointer(&ignore)))
+ if result == 0 {
+ panic(result)
+ }
+} \ No newline at end of file
diff --git a/vendor/github.com/agiledragon/gomonkey/patch.go b/vendor/github.com/agiledragon/gomonkey/patch.go
new file mode 100644
index 000000000..99df38851
--- /dev/null
+++ b/vendor/github.com/agiledragon/gomonkey/patch.go
@@ -0,0 +1,232 @@
+package gomonkey
+
+import (
+ "fmt"
+ "reflect"
+ "syscall"
+ "unsafe"
+)
+
+type Patches struct {
+ originals map[reflect.Value][]byte
+ values map[reflect.Value]reflect.Value
+ valueHolders map[reflect.Value]reflect.Value
+}
+
+type Params []interface{}
+type OutputCell struct {
+ Values Params
+ Times int
+}
+
+func ApplyFunc(target, double interface{}) *Patches {
+ return create().ApplyFunc(target, double)
+}
+
+func ApplyMethod(target reflect.Type, methodName string, double interface{}) *Patches {
+ return create().ApplyMethod(target, methodName, double)
+}
+
+func ApplyGlobalVar(target, double interface{}) *Patches {
+ return create().ApplyGlobalVar(target, double)
+}
+
+func ApplyFuncVar(target, double interface{}) *Patches {
+ return create().ApplyFuncVar(target, double)
+}
+
+func ApplyFuncSeq(target interface{}, outputs []OutputCell) *Patches {
+ return create().ApplyFuncSeq(target, outputs)
+}
+
+func ApplyMethodSeq(target reflect.Type, methodName string, outputs []OutputCell) *Patches {
+ return create().ApplyMethodSeq(target, methodName, outputs)
+}
+
+func ApplyFuncVarSeq(target interface{}, outputs []OutputCell) *Patches {
+ return create().ApplyFuncVarSeq(target, outputs)
+}
+
+func create() *Patches {
+ return &Patches{originals: make(map[reflect.Value][]byte), values: make(map[reflect.Value]reflect.Value), valueHolders: make(map[reflect.Value]reflect.Value)}
+}
+
+func NewPatches() *Patches {
+ return create()
+}
+
+func (this *Patches) ApplyFunc(target, double interface{}) *Patches {
+ t := reflect.ValueOf(target)
+ d := reflect.ValueOf(double)
+ return this.ApplyCore(t, d)
+}
+
+func (this *Patches) ApplyMethod(target reflect.Type, methodName string, double interface{}) *Patches {
+ m, ok := target.MethodByName(methodName)
+ if !ok {
+ panic("retrieve method by name failed")
+ }
+ d := reflect.ValueOf(double)
+ return this.ApplyCore(m.Func, d)
+}
+
+func (this *Patches) ApplyGlobalVar(target, double interface{}) *Patches {
+ t := reflect.ValueOf(target)
+ if t.Type().Kind() != reflect.Ptr {
+ panic("target is not a pointer")
+ }
+
+ this.values[t] = reflect.ValueOf(t.Elem().Interface())
+ d := reflect.ValueOf(double)
+ t.Elem().Set(d)
+ return this
+}
+
+func (this *Patches) ApplyFuncVar(target, double interface{}) *Patches {
+ t := reflect.ValueOf(target)
+ d := reflect.ValueOf(double)
+ if t.Type().Kind() != reflect.Ptr {
+ panic("target is not a pointer")
+ }
+ this.check(t.Elem(), d)
+ return this.ApplyGlobalVar(target, double)
+}
+
+func (this *Patches) ApplyFuncSeq(target interface{}, outputs []OutputCell) *Patches {
+ funcType := reflect.TypeOf(target)
+ t := reflect.ValueOf(target)
+ d := getDoubleFunc(funcType, outputs)
+ return this.ApplyCore(t, d)
+}
+
+func (this *Patches) ApplyMethodSeq(target reflect.Type, methodName string, outputs []OutputCell) *Patches {
+ m, ok := target.MethodByName(methodName)
+ if !ok {
+ panic("retrieve method by name failed")
+ }
+ d := getDoubleFunc(m.Type, outputs)
+ return this.ApplyCore(m.Func, d)
+}
+
+func (this *Patches) ApplyFuncVarSeq(target interface{}, outputs []OutputCell) *Patches {
+ t := reflect.ValueOf(target)
+ if t.Type().Kind() != reflect.Ptr {
+ panic("target is not a pointer")
+ }
+ if t.Elem().Kind() != reflect.Func {
+ panic("target is not a func")
+ }
+
+ funcType := reflect.TypeOf(target).Elem()
+ double := getDoubleFunc(funcType, outputs).Interface()
+ return this.ApplyGlobalVar(target, double)
+}
+
+func (this *Patches) Reset() {
+ for target, bytes := range this.originals {
+ modifyBinary(*(*uintptr)(getPointer(target)), bytes)
+ delete(this.originals, target)
+ }
+
+ for target, variable := range this.values {
+ target.Elem().Set(variable)
+ }
+}
+
+func (this *Patches) ApplyCore(target, double reflect.Value) *Patches {
+ this.check(target, double)
+ if _, ok := this.originals[target]; ok {
+ panic("patch has been existed")
+ }
+
+ this.valueHolders[double] = double
+ original := replace(*(*uintptr)(getPointer(target)), uintptr(getPointer(double)))
+ this.originals[target] = original
+ return this
+}
+
+func (this *Patches) check(target, double reflect.Value) {
+ if target.Kind() != reflect.Func {
+ panic("target is not a func")
+ }
+
+ if double.Kind() != reflect.Func {
+ panic("double is not a func")
+ }
+
+ if target.Type() != double.Type() {
+ panic(fmt.Sprintf("target type(%s) and double type(%s) are different", target.Type(), double.Type()))
+ }
+}
+
+func replace(target, double uintptr) []byte {
+ code := buildJmpDirective(double)
+ bytes := entryAddress(target, len(code))
+ original := make([]byte, len(bytes))
+ copy(original, bytes)
+ modifyBinary(target, code)
+ return original
+}
+
+func getDoubleFunc(funcType reflect.Type, outputs []OutputCell) reflect.Value {
+ if funcType.NumOut() != len(outputs[0].Values) {
+ panic(fmt.Sprintf("func type has %v return values, but only %v values provided as double",
+ funcType.NumOut(), len(outputs[0].Values)))
+ }
+
+ slice := make([]Params, 0)
+ for _, output := range outputs {
+ t := 0
+ if output.Times <= 1 {
+ t = 1
+ } else {
+ t = output.Times
+ }
+ for j := 0; j < t; j++ {
+ slice = append(slice, output.Values)
+ }
+ }
+
+ i := 0
+ len := len(slice)
+ return reflect.MakeFunc(funcType, func(_ []reflect.Value) []reflect.Value {
+ if i < len {
+ i++
+ return GetResultValues(funcType, slice[i-1]...)
+ }
+ panic("double seq is less than call seq")
+ })
+}
+
+func GetResultValues(funcType reflect.Type, results ...interface{}) []reflect.Value {
+ var resultValues []reflect.Value
+ for i, r := range results {
+ var resultValue reflect.Value
+ if r == nil {
+ resultValue = reflect.Zero(funcType.Out(i))
+ } else {
+ v := reflect.New(funcType.Out(i))
+ v.Elem().Set(reflect.ValueOf(r))
+ resultValue = v.Elem()
+ }
+ resultValues = append(resultValues, resultValue)
+ }
+ return resultValues
+}
+
+type funcValue struct {
+ _ uintptr
+ p unsafe.Pointer
+}
+
+func getPointer(v reflect.Value) unsafe.Pointer {
+ return (*funcValue)(unsafe.Pointer(&v)).p
+}
+
+func entryAddress(p uintptr, l int) []byte {
+ return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{Data: p, Len: l, Cap: l}))
+}
+
+func pageStart(ptr uintptr) uintptr {
+ return ptr & ^(uintptr(syscall.Getpagesize() - 1))
+}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 31fe74b50..04b7708c8 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -103,6 +103,9 @@ github.com/Microsoft/hcsshim/osversion
# github.com/NYTimes/gziphandler v1.1.1
## explicit; go 1.11
github.com/NYTimes/gziphandler
+# github.com/agiledragon/gomonkey v2.0.2+incompatible
+## explicit
+github.com/agiledragon/gomonkey
# github.com/antlr/antlr4/runtime/Go/antlr v1.4.10
## explicit; go 1.16
github.com/antlr/antlr4/runtime/Go/antlr