Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Add streaming Test #224

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 120 additions & 7 deletions pkg/hyper/fake_client_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ type fakeClientInterface struct {
imageInfoList []*types.ImageInfo
version string
apiVersion string
execCmd map[string]*[]string
}

func newFakeClientInterface(c clock.Clock) *fakeClientInterface {
return &fakeClientInterface{
Clock: c,
containerInfoMap: make(map[string]*types.ContainerInfo),
podInfoMap: make(map[string]*types.PodInfo),
execCmd: make(map[string]*[]string),
}
}

type FakePod struct {
PodID string
Status string
PodVolume []*types.PodVolume
}

Expand All @@ -63,8 +66,12 @@ func (f *fakeClientInterface) SetFakePod(pods []*FakePod) {
podSpec := types.PodSpec{
Volumes: p.PodVolume,
}
podStatus := types.PodStatus{
Phase: p.Status,
}
podInfo := types.PodInfo{
Spec: &podSpec,
Spec: &podSpec,
Status: &podStatus,
}

f.podInfoMap[p.PodID] = &podInfo
Expand All @@ -78,6 +85,36 @@ func (f *fakeClientInterface) SetVersion(version string, apiVersion string) {
f.apiVersion = apiVersion
}

type FakeContainer struct {
ID string
Name string
Status string
PodID string
}

func (f *fakeClientInterface) SetFakeContainers(containers []*FakeContainer) {
f.Lock()
defer f.Unlock()
for i := range containers {
c := containers[i]
container := types.Container{
Name: c.Name,
ContainerID: c.ID,
}
containerStatus := types.ContainerStatus{
ContainerID: c.ID,
Phase: c.Status,
}
containerInfo := types.ContainerInfo{
Container: &container,
Status: &containerStatus,
PodID: c.PodID,
}
f.containerInfoMap[c.ID] = &containerInfo
}

}

func (f *fakeClientInterface) CleanCalls() {
f.Lock()
defer f.Unlock()
Expand Down Expand Up @@ -128,8 +165,28 @@ func (f *fakeClientInterface) PodUnpause(ctx context.Context, in *types.PodUnpau
return nil, fmt.Errorf("Not implemented")
}

type fakePublicAPI_ExecVMClient struct {
grpc.ClientStream
}

func (x *fakePublicAPI_ExecVMClient) Send(m *types.ExecVMRequest) error {
return nil
}

func (x *fakePublicAPI_ExecVMClient) Recv() (*types.ExecVMResponse, error) {
m := &types.ExecVMResponse{}
return m, io.EOF
}

func (x *fakePublicAPI_ExecVMClient) CloseSend() error {
return nil
}

func (f *fakeClientInterface) ExecVM(ctx context.Context, opts ...grpc.CallOption) (types.PublicAPI_ExecVMClient, error) {
return nil, fmt.Errorf("Not implemented")
f.Lock()
defer f.Unlock()
f.called = append(f.called, "ExecVM")
return &fakePublicAPI_ExecVMClient{}, f.err
}

func (f *fakeClientInterface) ContainerList(ctx context.Context, in *types.ContainerListRequest, opts ...grpc.CallOption) (*types.ContainerListResponse, error) {
Expand Down Expand Up @@ -282,27 +339,83 @@ func (f *fakeClientInterface) ContainerRemove(ctx context.Context, in *types.Con
}

func (f *fakeClientInterface) ExecCreate(ctx context.Context, in *types.ExecCreateRequest, opts ...grpc.CallOption) (*types.ExecCreateResponse, error) {
return nil, fmt.Errorf("Not implemented")
f.Lock()
defer f.Unlock()
f.called = append(f.called, "ExecCreate")
containerId := in.ContainerID
f.execCmd[containerId] = &in.Command
//The container's name is "sidecar" + i,we use i as the execID
ids := strings.Split(containerId, "*")
execID := ids[1]
return &types.ExecCreateResponse{
ExecID: execID,
}, f.err
}

type fakePublicAPI_ExecStartClient struct {
grpc.ClientStream
}

func (x *fakePublicAPI_ExecStartClient) Send(m *types.ExecStartRequest) error {
return nil
}

func (x *fakePublicAPI_ExecStartClient) Recv() (*types.ExecStartResponse, error) {
m := &types.ExecStartResponse{}
return m, io.EOF
}

func (x *fakePublicAPI_ExecStartClient) CloseSend() error {
return nil
}

func (f *fakeClientInterface) ExecStart(ctx context.Context, opts ...grpc.CallOption) (types.PublicAPI_ExecStartClient, error) {
return nil, fmt.Errorf("Not implemented")
f.Lock()
defer f.Unlock()
f.called = append(f.called, "ExecStart")
return &fakePublicAPI_ExecStartClient{}, f.err
}

func (f *fakeClientInterface) ExecSignal(ctx context.Context, in *types.ExecSignalRequest, opts ...grpc.CallOption) (*types.ExecSignalResponse, error) {
return nil, fmt.Errorf("Not implemented")
}

type fakePublicAPI_AttachClient struct {
grpc.ClientStream
}

func (x *fakePublicAPI_AttachClient) Send(m *types.AttachMessage) error {
return nil
}

func (x *fakePublicAPI_AttachClient) Recv() (*types.AttachMessage, error) {
m := &types.AttachMessage{}
return m, io.EOF
}

func (x *fakePublicAPI_AttachClient) CloseSend() error {
return nil
}

func (f *fakeClientInterface) Attach(ctx context.Context, opts ...grpc.CallOption) (types.PublicAPI_AttachClient, error) {
return nil, fmt.Errorf("Not implemented")
f.Lock()
defer f.Unlock()
f.called = append(f.called, "Attach")
return &fakePublicAPI_AttachClient{}, f.err
}

func (f *fakeClientInterface) Wait(ctx context.Context, in *types.WaitRequest, opts ...grpc.CallOption) (*types.WaitResponse, error) {
return nil, fmt.Errorf("Not implemented")
f.Lock()
defer f.Unlock()
f.called = append(f.called, "Wait")
return &types.WaitResponse{}, f.err
}

func (f *fakeClientInterface) TTYResize(ctx context.Context, in *types.TTYResizeRequest, opts ...grpc.CallOption) (*types.TTYResizeResponse, error) {
return nil, fmt.Errorf("Not implemented")
f.Lock()
defer f.Unlock()
f.called = append(f.called, "TTYResize")
return &types.TTYResizeResponse{}, nil
}

func (f *fakeClientInterface) ServiceList(ctx context.Context, in *types.ServiceListRequest, opts ...grpc.CallOption) (*types.ServiceListResponse, error) {
Expand Down
Loading