Skip to content

Commit

Permalink
cleanup: rm runtime.Caller with const func name
Browse files Browse the repository at this point in the history
Signed-off-by: zhangyue <zy675793960@yeah.net>
  • Loading branch information
zhangyue authored and fuweid committed Dec 2, 2018
1 parent d7d94df commit cb5f222
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 168 deletions.
17 changes: 2 additions & 15 deletions test/cli_alikernel_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
"runtime"
"strings"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"

Expand Down Expand Up @@ -34,12 +31,7 @@ func (suite *PouchAliKernelSuite) TearDownTest(c *check.C) {

// TestAliKernelDiskQuotaWorks tests disk quota works on AliKernel.
func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaWorks(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestAliKernelDiskQuotaWorks"

command.PouchRun("volume", "create", "--name", funcname, "-d", "local", "-o", "opt.size=1g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", funcname)
Expand All @@ -66,12 +58,7 @@ func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaWorks(c *check.C) {

// TestAliKernelDiskQuotaMultiWorks tests multi volume with different disk quota works on AliKernel.
func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaMultiWorks(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestAliKernelDiskQuotaMultiWorks"

name1 := funcname + "1"
name2 := funcname + "2"
Expand Down
10 changes: 2 additions & 8 deletions test/cli_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"reflect"
"runtime"
"strings"

"github.com/alibaba/pouch/apis/types"
Expand All @@ -14,7 +13,7 @@ import (

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/go-digest"
)

// PouchCreateSuite is the test suite for create CLI.
Expand Down Expand Up @@ -109,12 +108,7 @@ func (suite *PouchCreateSuite) TestCreateWithTTY(c *check.C) {
//
// TODO: pouch inspect should return volume info to check
func (suite *PouchCreateSuite) TestPouchCreateVolume(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestPouchCreateVolume"

res := command.PouchRun("create", "-v /tmp:/tmp", "--name", funcname, busyboxImage)
defer DelContainerForceMultyTime(c, funcname)
Expand Down
43 changes: 6 additions & 37 deletions test/cli_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -57,12 +56,7 @@ func (suite *PouchNetworkSuite) TestNetworkInspectFormat(c *check.C) {

// TestNetworkDefault tests the creation of default bridge/none/host network.
func (suite *PouchNetworkSuite) TestNetworkDefault(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestNetworkDefault"

// After pouchd is launched, default network bridge is created
// check the existence of default network: bridge
Expand Down Expand Up @@ -109,12 +103,7 @@ func (suite *PouchNetworkSuite) TestNetworkDefault(c *check.C) {

// TestNetworkBridgeWorks tests bridge network works.
func (suite *PouchNetworkSuite) TestNetworkBridgeWorks(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestNetworkBridgeWorks"

// Remove network in case there is legacy network which may impacts test.
defer command.PouchRun("network", "remove", funcname)
Expand Down Expand Up @@ -225,12 +214,7 @@ func (suite *PouchNetworkSuite) TestNetworkBridgeWorks(c *check.C) {

// TestNetworkCreateWrongDriver tests using wrong driver returns error.
func (suite *PouchNetworkSuite) TestNetworkCreateWrongDriver(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestNetworkCreateWrongDriver"

expct := icmd.Expected{
ExitCode: 1,
Expand All @@ -245,12 +229,7 @@ func (suite *PouchNetworkSuite) TestNetworkCreateWrongDriver(c *check.C) {

// TestNetworkCreateWithLabel tests creating network with label.
func (suite *PouchNetworkSuite) TestNetworkCreateWithLabel(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestNetworkCreateWithLabel"

tests := []struct {
name string
Expand Down Expand Up @@ -304,12 +283,7 @@ func (suite *PouchNetworkSuite) TestNetworkCreateWithLabel(c *check.C) {

// TestNetworkCreateWithOption tests creating network with option.
func (suite *PouchNetworkSuite) TestNetworkCreateWithOption(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestNetworkCreateWithOption"

tests := []struct {
name string
Expand Down Expand Up @@ -384,12 +358,7 @@ func (suite *PouchNetworkSuite) TestNetworkCreateWithIPAMOption(c *check.C) {

// TestNetworkCreateDup tests creating duplicate network return error.
func (suite *PouchNetworkSuite) TestNetworkCreateDup(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestNetworkCreateDup"

expct := icmd.Expected{
ExitCode: 1,
Expand Down
22 changes: 3 additions & 19 deletions test/cli_rich_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"runtime"
"strings"

"github.com/alibaba/pouch/apis/types"
Expand Down Expand Up @@ -106,12 +105,7 @@ func checkInitScriptWorks(c *check.C, cname string, image string, richmode strin
// TestRichContainerDumbInitWorks check the dumb-init works.
func (suite *PouchRichContainerSuite) TestRichContainerDumbInitWorks(c *check.C) {
SkipIfFalse(c, environment.IsDumbInitExist)
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestRichContainerDumbInitWorks"

res := command.PouchRun("run", "-d", "--rich", "--rich-mode", "dumb-init", "--name", funcname,
busyboxImage, "sleep", "10000")
Expand Down Expand Up @@ -154,12 +148,7 @@ Comment the test (Ace-Tang).
related issue : https://github.com/alibaba/pouch/issues/960
related pr: https://github.com/alibaba/pouch/pull/1128
func (suite *PouchRichContainerSuite) TestRichContainerInitdWorks(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestRichContainerInitdWorks"
ok, _ := isFileExistsInImage(centosImage, "/sbin/init", "checkinit")
if !ok {
Expand Down Expand Up @@ -202,12 +191,7 @@ func (suite *PouchRichContainerSuite) TestRichContainerSystemdWorks(c *check.C)
// TODO: uncomment it
c.Skip("skip this flaky test")

pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestRichContainerSystemdWorks"

ok, _ := isFileExistsInImage(centosImage, "/usr/lib/systemd/systemd", "checksysd")
if !ok {
Expand Down
13 changes: 3 additions & 10 deletions test/cli_run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"runtime"
"strings"

"github.com/alibaba/pouch/apis/types"
Expand Down Expand Up @@ -36,14 +35,8 @@ func (suite *PouchRunVolumeSuite) TearDownTest(c *check.C) {

// TestRunWithLocalVolume is to verify run container with -v volume works.
func (suite *PouchRunVolumeSuite) TestRunWithLocalVolume(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
funcname := "TestRunWithLocalVolume"

name := funcname
{
res := command.PouchRun("volume", "create", "--name", funcname)
defer func() {
Expand All @@ -53,9 +46,9 @@ func (suite *PouchRunVolumeSuite) TestRunWithLocalVolume(c *check.C) {
}

{
res := command.PouchRun("run", "--name", name, "-v", funcname+":/tmp",
res := command.PouchRun("run", "--name", funcname, "-v", funcname+":/tmp",
busyboxImage, "touch", "/tmp/test")
defer DelContainerForceMultyTime(c, name)
defer DelContainerForceMultyTime(c, funcname)
res.Assert(c, icmd.Success)
}

Expand Down
Loading

0 comments on commit cb5f222

Please sign in to comment.