forked from kata-containers/runtime
-
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.
add UTs for network hotplug related fuctions Fixes kata-containers#113 Signed-off-by: Ruidong Cao <[email protected]>
- Loading branch information
1 parent
9334c05
commit 5d64559
Showing
6 changed files
with
316 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"github.com/kata-containers/agent/protocols/grpc" | ||
vc "github.com/kata-containers/runtime/virtcontainers" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var testAddInterfaceFuncReturnNil = func(sid string, inf *grpc.Interface) (*grpc.Interface, error) { | ||
return nil, nil | ||
} | ||
|
||
func TestNetworkCliAction(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
flagSet := flag.NewFlagSet("kata-network", flag.ContinueOnError) | ||
|
||
// create a new fake context | ||
ctx := createCLIContext(flagSet) | ||
|
||
// get Action function | ||
actionFunc, ok := addIfaceCommand.Action.(func(ctx *cli.Context) error) | ||
assert.True(ok) | ||
|
||
err := actionFunc(ctx) | ||
assert.Error(err, "Missing container ID") | ||
} | ||
|
||
func TestNetwrokCliFunctionAddInterface(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
state := vc.State{ | ||
State: vc.StateRunning, | ||
} | ||
|
||
testingImpl.AddInterfaceFunc = testAddInterfaceFuncReturnNil | ||
|
||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID) | ||
assert.NoError(err) | ||
defer os.RemoveAll(path) | ||
|
||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) { | ||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil | ||
} | ||
|
||
defer func() { | ||
testingImpl.AddInterfaceFunc = nil | ||
testingImpl.StatusContainerFunc = nil | ||
}() | ||
|
||
set := flag.NewFlagSet("", 0) | ||
|
||
execCLICommandFunc(assert, addIfaceCommand, set, true) | ||
} |
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
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