* Add Playground struct and basic support for creating it and retrieving it * Add missing functions in pwd mock * Get playground from request domain and validate it exists. If valid set it on the newly created session. * Move playground specific configurations to the playground struct and use it everytime we need that conf. * Don't allow to specify a duration bigger that the allowed in the playground
146 lines
4.1 KiB
Go
146 lines
4.1 KiB
Go
package pwd
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/play-with-docker/play-with-docker/pwd/types"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
type Mock struct {
|
|
mock.Mock
|
|
}
|
|
|
|
func (m *Mock) SessionNew(playground *types.Playground, userId string, duration time.Duration, stack string, stackName, imageName string) (*types.Session, error) {
|
|
args := m.Called(duration, stack, stackName, imageName)
|
|
return args.Get(0).(*types.Session), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) SessionClose(session *types.Session) error {
|
|
args := m.Called(session)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) SessionGetSmallestViewPort(sessionId string) types.ViewPort {
|
|
args := m.Called(sessionId)
|
|
return args.Get(0).(types.ViewPort)
|
|
}
|
|
|
|
func (m *Mock) SessionDeployStack(session *types.Session) error {
|
|
args := m.Called(session)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) SessionGet(id string) *types.Session {
|
|
args := m.Called(id)
|
|
return args.Get(0).(*types.Session)
|
|
}
|
|
|
|
func (m *Mock) SessionSetup(session *types.Session, conf SessionSetupConf) error {
|
|
args := m.Called(session, conf)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) InstanceNew(session *types.Session, conf types.InstanceConfig) (*types.Instance, error) {
|
|
args := m.Called(session, conf)
|
|
return args.Get(0).(*types.Instance), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) InstanceResizeTerminal(instance *types.Instance, cols, rows uint) error {
|
|
args := m.Called(instance, cols, rows)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) InstanceGetTerminal(instance *types.Instance) (net.Conn, error) {
|
|
args := m.Called(instance)
|
|
return args.Get(0).(net.Conn), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) InstanceUploadFromUrl(instance *types.Instance, fileName, dest, url string) error {
|
|
args := m.Called(instance, fileName, dest, url)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) InstanceUploadFromReader(instance *types.Instance, fileName, dest string, reader io.Reader) error {
|
|
args := m.Called(instance, fileName, dest, reader)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) InstanceGet(session *types.Session, name string) *types.Instance {
|
|
args := m.Called(session, name)
|
|
return args.Get(0).(*types.Instance)
|
|
}
|
|
func (m *Mock) InstanceFindBySession(session *types.Session) ([]*types.Instance, error) {
|
|
args := m.Called(session)
|
|
return args.Get(0).([]*types.Instance), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) InstanceDelete(session *types.Session, instance *types.Instance) error {
|
|
args := m.Called(session, instance)
|
|
return args.Error(0)
|
|
}
|
|
|
|
func (m *Mock) InstanceExec(instance *types.Instance, cmd []string) (int, error) {
|
|
args := m.Called(instance, cmd)
|
|
return args.Int(0), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) ClientNew(id string, session *types.Session) *types.Client {
|
|
args := m.Called(id, session)
|
|
return args.Get(0).(*types.Client)
|
|
}
|
|
|
|
func (m *Mock) ClientResizeViewPort(client *types.Client, cols, rows uint) {
|
|
m.Called(client, cols, rows)
|
|
}
|
|
|
|
func (m *Mock) ClientClose(client *types.Client) {
|
|
m.Called(client)
|
|
}
|
|
|
|
func (m *Mock) ClientCount() int {
|
|
args := m.Called()
|
|
return args.Int(0)
|
|
}
|
|
|
|
func (m *Mock) UserNewLoginRequest(providerName string) (*types.LoginRequest, error) {
|
|
args := m.Called(providerName)
|
|
return args.Get(0).(*types.LoginRequest), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) UserGetLoginRequest(id string) (*types.LoginRequest, error) {
|
|
args := m.Called(id)
|
|
return args.Get(0).(*types.LoginRequest), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) UserLogin(loginRequest *types.LoginRequest, user *types.User) (*types.User, error) {
|
|
args := m.Called(loginRequest, user)
|
|
return args.Get(0).(*types.User), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) UserGet(id string) (*types.User, error) {
|
|
args := m.Called(id)
|
|
return args.Get(0).(*types.User), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) PlaygroundNew(playground types.Playground) (*types.Playground, error) {
|
|
args := m.Called(playground)
|
|
return args.Get(0).(*types.Playground), args.Error(1)
|
|
}
|
|
|
|
func (m *Mock) PlaygroundGet(id string) *types.Playground {
|
|
args := m.Called(id)
|
|
return args.Get(0).(*types.Playground)
|
|
}
|
|
|
|
func (m *Mock) PlaygroundFindByDomain(domain string) *types.Playground {
|
|
args := m.Called(domain)
|
|
return args.Get(0).(*types.Playground)
|
|
}
|
|
func (m *Mock) PlaygroundList() ([]*types.Playground, error) {
|
|
args := m.Called()
|
|
return args.Get(0).([]*types.Playground), args.Error(1)
|
|
}
|