Add test for InstanceResizeTerminal
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
)
|
||||
|
||||
type mockDocker struct {
|
||||
createNetwork func(string) error
|
||||
connectNetwork func(container, network, ip string) (string, error)
|
||||
createNetwork func(string) error
|
||||
connectNetwork func(container, network, ip string) (string, error)
|
||||
containerResize func(string, uint, uint) error
|
||||
}
|
||||
|
||||
func (m *mockDocker) CreateNetwork(id string) error {
|
||||
@@ -40,6 +41,9 @@ func (m *mockDocker) GetContainerStats(name string) (io.ReadCloser, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (m *mockDocker) ContainerResize(name string, rows, cols uint) error {
|
||||
if m.containerResize != nil {
|
||||
return m.containerResize(name, rows, cols)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *mockDocker) CreateAttachConnection(name string) (net.Conn, error) {
|
||||
|
||||
35
pwd/instance_test.go
Normal file
35
pwd/instance_test.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user