Use a strong type for UID fields
This commit is contained in:
@@ -29,18 +29,19 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/google/cadvisor/info"
|
||||
)
|
||||
|
||||
type fakeKubelet struct {
|
||||
podByNameFunc func(namespace, name string) (*api.BoundPod, bool)
|
||||
infoFunc func(name string) (api.PodInfo, error)
|
||||
containerInfoFunc func(podFullName, uid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||
containerInfoFunc func(podFullName string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||
rootInfoFunc func(query *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||
machineInfoFunc func() (*info.MachineInfo, error)
|
||||
boundPodsFunc func() ([]api.BoundPod, error)
|
||||
logFunc func(w http.ResponseWriter, req *http.Request)
|
||||
runFunc func(podFullName, uuid, containerName string, cmd []string) ([]byte, error)
|
||||
runFunc func(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error)
|
||||
containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
|
||||
}
|
||||
|
||||
@@ -48,12 +49,12 @@ func (fk *fakeKubelet) GetPodByName(namespace, name string) (*api.BoundPod, bool
|
||||
return fk.podByNameFunc(namespace, name)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
|
||||
func (fk *fakeKubelet) GetPodInfo(name string, uid util.UID) (api.PodInfo, error) {
|
||||
return fk.infoFunc(name)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetContainerInfo(podFullName, uuid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
return fk.containerInfoFunc(podFullName, uuid, containerName, req)
|
||||
func (fk *fakeKubelet) GetContainerInfo(podFullName string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
return fk.containerInfoFunc(podFullName, uid, containerName, req)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
@@ -76,8 +77,8 @@ func (fk *fakeKubelet) GetKubeletContainerLogs(podFullName, containerName, tail
|
||||
return fk.containerLogsFunc(podFullName, containerName, tail, follow, stdout, stderr)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||
return fk.runFunc(podFullName, uuid, containerName, cmd)
|
||||
func (fk *fakeKubelet) RunInContainer(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) {
|
||||
return fk.runFunc(podFullName, uid, containerName, cmd)
|
||||
}
|
||||
|
||||
type serverTestFramework struct {
|
||||
@@ -161,7 +162,7 @@ func TestContainerInfo(t *testing.T) {
|
||||
podID := "somepod"
|
||||
expectedPodID := "somepod" + ".default.etcd"
|
||||
expectedContainerName := "goodcontainer"
|
||||
fw.fakeKubelet.containerInfoFunc = func(podID, uid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
fw.fakeKubelet.containerInfoFunc = func(podID string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
if podID != expectedPodID || containerName != expectedContainerName {
|
||||
return nil, fmt.Errorf("bad podID or containerName: podID=%v; containerName=%v", podID, containerName)
|
||||
}
|
||||
@@ -191,8 +192,8 @@ func TestContainerInfoWithUidNamespace(t *testing.T) {
|
||||
expectedPodID := "somepod" + "." + expectedNamespace + ".etcd"
|
||||
expectedContainerName := "goodcontainer"
|
||||
expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647"
|
||||
fw.fakeKubelet.containerInfoFunc = func(podID, uid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
if podID != expectedPodID || uid != expectedUid || containerName != expectedContainerName {
|
||||
fw.fakeKubelet.containerInfoFunc = func(podID string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
if podID != expectedPodID || string(uid) != expectedUid || containerName != expectedContainerName {
|
||||
return nil, fmt.Errorf("bad podID or uid or containerName: podID=%v; uid=%v; containerName=%v", podID, uid, containerName)
|
||||
}
|
||||
return expectedInfo, nil
|
||||
@@ -296,7 +297,7 @@ func TestServeRunInContainer(t *testing.T) {
|
||||
expectedPodName := podName + "." + podNamespace + ".etcd"
|
||||
expectedContainerName := "baz"
|
||||
expectedCommand := "ls -a"
|
||||
fw.fakeKubelet.runFunc = func(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||
fw.fakeKubelet.runFunc = func(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) {
|
||||
if podFullName != expectedPodName {
|
||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||
}
|
||||
@@ -328,21 +329,21 @@ func TestServeRunInContainer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeRunInContainerWithUUID(t *testing.T) {
|
||||
func TestServeRunInContainerWithUID(t *testing.T) {
|
||||
fw := newServerTest()
|
||||
output := "foo bar"
|
||||
podNamespace := "other"
|
||||
podName := "foo"
|
||||
expectedPodName := podName + "." + podNamespace + ".etcd"
|
||||
expectedUuid := "7e00838d_-_3523_-_11e4_-_8421_-_42010af0a720"
|
||||
expectedUID := "7e00838d_-_3523_-_11e4_-_8421_-_42010af0a720"
|
||||
expectedContainerName := "baz"
|
||||
expectedCommand := "ls -a"
|
||||
fw.fakeKubelet.runFunc = func(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||
fw.fakeKubelet.runFunc = func(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) {
|
||||
if podFullName != expectedPodName {
|
||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||
}
|
||||
if uuid != expectedUuid {
|
||||
t.Errorf("expected %s, got %s", expectedUuid, uuid)
|
||||
if string(uid) != expectedUID {
|
||||
t.Errorf("expected %s, got %s", expectedUID, uid)
|
||||
}
|
||||
if containerName != expectedContainerName {
|
||||
t.Errorf("expected %s, got %s", expectedContainerName, containerName)
|
||||
@@ -354,7 +355,7 @@ func TestServeRunInContainerWithUUID(t *testing.T) {
|
||||
return []byte(output), nil
|
||||
}
|
||||
|
||||
resp, err := http.Get(fw.testHTTPServer.URL + "/run/" + podNamespace + "/" + podName + "/" + expectedUuid + "/" + expectedContainerName + "?cmd=ls%20-a")
|
||||
resp, err := http.Get(fw.testHTTPServer.URL + "/run/" + podNamespace + "/" + podName + "/" + expectedUID + "/" + expectedContainerName + "?cmd=ls%20-a")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Got error GETing: %v", err)
|
||||
|
Reference in New Issue
Block a user