forked from moby/libnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request moby#1893 from fcrisciani/service-issue
Service connectivity issue
- Loading branch information
Showing
9 changed files
with
224 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package common | ||
|
||
import ( | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
func callerInfo(i int) string { | ||
ptr, _, _, ok := runtime.Caller(i) | ||
fName := "unknown" | ||
if ok { | ||
f := runtime.FuncForPC(ptr) | ||
if f != nil { | ||
// f.Name() is like: github.com/docker/libnetwork/common.MethodName | ||
tmp := strings.Split(f.Name(), ".") | ||
if len(tmp) > 0 { | ||
fName = tmp[len(tmp)-1] | ||
} | ||
} | ||
} | ||
|
||
return fName | ||
} | ||
|
||
// CallerName returns the name of the function at the specified level | ||
// level == 0 means current method name | ||
func CallerName(level int) string { | ||
return callerInfo(2 + level) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package common | ||
|
||
import "testing" | ||
|
||
func fun1() string { | ||
return CallerName(0) | ||
} | ||
|
||
func fun2() string { | ||
return CallerName(1) | ||
} | ||
|
||
func fun3() string { | ||
return fun4() | ||
} | ||
|
||
func fun4() string { | ||
return CallerName(0) | ||
} | ||
|
||
func fun5() string { | ||
return fun6() | ||
} | ||
|
||
func fun6() string { | ||
return CallerName(1) | ||
} | ||
|
||
func TestCaller(t *testing.T) { | ||
funName := fun1() | ||
if funName != "fun1" { | ||
t.Fatalf("error on fun1 caller %s", funName) | ||
} | ||
|
||
funName = fun2() | ||
if funName != "TestCaller" { | ||
t.Fatalf("error on fun2 caller %s", funName) | ||
} | ||
|
||
funName = fun3() | ||
if funName != "fun4" { | ||
t.Fatalf("error on fun2 caller %s", funName) | ||
} | ||
|
||
funName = fun5() | ||
if funName != "fun5" { | ||
t.Fatalf("error on fun5 caller %s", funName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.