Add test for InstanceResizeTerminal

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-05-26 10:01:38 -03:00
parent 824647b97d
commit dfbf870383
2 changed files with 41 additions and 2 deletions

View File

@@ -9,8 +9,9 @@ import (
) )
type mockDocker struct { type mockDocker struct {
createNetwork func(string) error createNetwork func(string) error
connectNetwork func(container, network, ip string) (string, error) connectNetwork func(container, network, ip string) (string, error)
containerResize func(string, uint, uint) error
} }
func (m *mockDocker) CreateNetwork(id string) error { func (m *mockDocker) CreateNetwork(id string) error {
@@ -40,6 +41,9 @@ func (m *mockDocker) GetContainerStats(name string) (io.ReadCloser, error) {
return nil, nil return nil, nil
} }
func (m *mockDocker) ContainerResize(name string, rows, cols uint) error { func (m *mockDocker) ContainerResize(name string, rows, cols uint) error {
if m.containerResize != nil {
return m.containerResize(name, rows, cols)
}
return nil return nil
} }
func (m *mockDocker) CreateAttachConnection(name string) (net.Conn, error) { func (m *mockDocker) CreateAttachConnection(name string) (net.Conn, error) {

35
pwd/instance_test.go Normal file
View File

@@ -0,0 +1,35 @@
package pwd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestInstanceResizeTerminal(t *testing.T) {
resizedInstanceName := ""
resizedRows := uint(0)
resizedCols := uint(0)
docker := &mockDocker{}
docker.containerResize = func(name string, rows, cols uint) error {
resizedInstanceName = name
resizedRows = rows
resizedCols = cols
return nil
}
tasks := &mockTasks{}
broadcast := &mockBroadcast{}
storage := &mockStorage{}
p := NewPWD(docker, tasks, broadcast, storage)
err := p.InstanceResizeTerminal(&Instance{Name: "foobar"}, 24, 80)
assert.Nil(t, err)
assert.Equal(t, "foobar", resizedInstanceName)
assert.Equal(t, uint(24), resizedRows)
assert.Equal(t, uint(80), resizedCols)
}