mirror of
https://github.com/FlipsideCrypto/convox.git
synced 2026-02-06 19:07:13 +00:00
119 lines
4.2 KiB
Go
119 lines
4.2 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/convox/convox/pkg/cli"
|
|
mocksdk "github.com/convox/convox/pkg/mock/sdk"
|
|
"github.com/convox/convox/pkg/options"
|
|
"github.com/convox/convox/pkg/structs"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestScale(t *testing.T) {
|
|
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
|
|
i.On("SystemGet").Return(fxSystem(), nil)
|
|
i.On("ServiceList", "app1").Return(structs.Services{*fxService(), *fxService()}, nil)
|
|
i.On("ProcessList", "app1", structs.ProcessListOptions{}).Return(structs.Processes{*fxProcess(), *fxProcess()}, nil)
|
|
|
|
res, err := testExecute(e, "scale -a app1", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, res.Code)
|
|
res.RequireStderr(t, []string{""})
|
|
res.RequireStdout(t, []string{
|
|
"SERVICE DESIRED RUNNING CPU MEMORY",
|
|
"service1 1 0 2 3 ",
|
|
"service1 1 0 2 3 ",
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestScaleError(t *testing.T) {
|
|
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
|
|
i.On("SystemGet").Return(fxSystem(), nil)
|
|
i.On("ServiceList", "app1").Return(nil, fmt.Errorf("err1"))
|
|
|
|
res, err := testExecute(e, "scale -a app1", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, res.Code)
|
|
res.RequireStderr(t, []string{"ERROR: err1"})
|
|
res.RequireStdout(t, []string{""})
|
|
})
|
|
}
|
|
|
|
func TestScaleClassic(t *testing.T) {
|
|
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
|
|
i.On("SystemGet").Return(fxSystemClassic(), nil)
|
|
i.On("FormationGet", "app1").Return(structs.Services{*fxService(), *fxService()}, nil)
|
|
i.On("ProcessList", "app1", structs.ProcessListOptions{}).Return(structs.Processes{*fxProcess(), *fxProcess()}, nil)
|
|
|
|
res, err := testExecute(e, "scale -a app1", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, res.Code)
|
|
res.RequireStderr(t, []string{""})
|
|
res.RequireStdout(t, []string{
|
|
"SERVICE DESIRED RUNNING CPU MEMORY",
|
|
"service1 1 0 2 3 ",
|
|
"service1 1 0 2 3 ",
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestScaleUpdate(t *testing.T) {
|
|
testClientWait(t, 50*time.Millisecond, func(e *cli.Engine, i *mocksdk.Interface) {
|
|
i.On("SystemGet").Return(fxSystem(), nil)
|
|
i.On("ServiceUpdate", "app1", "web", structs.ServiceUpdateOptions{Count: options.Int(3), Cpu: options.Int(5), Memory: options.Int(10)}).Return(nil)
|
|
i.On("AppGet", "app1").Return(fxAppUpdating(), nil).Twice()
|
|
i.On("AppGet", "app1").Return(fxApp(), nil)
|
|
i.On("AppLogs", "app1", mock.Anything).Return(testLogs(fxLogsSystem()), nil)
|
|
|
|
res, err := testExecute(e, "scale web --cpu 5 --memory 10 --count 3 -a app1", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, res.Code)
|
|
res.RequireStderr(t, []string{""})
|
|
res.RequireStdout(t, []string{
|
|
"Scaling web... ",
|
|
"TIME system/aws/component log1",
|
|
"TIME system/aws/component log2",
|
|
"OK",
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestScaleUpdateError(t *testing.T) {
|
|
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
|
|
i.On("SystemGet").Return(fxSystem(), nil)
|
|
i.On("ServiceUpdate", "app1", "web", structs.ServiceUpdateOptions{Count: options.Int(3), Cpu: options.Int(5), Memory: options.Int(10)}).Return(fmt.Errorf("err1"))
|
|
|
|
res, err := testExecute(e, "scale web --cpu 5 --memory 10 --count 3 -a app1", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, res.Code)
|
|
res.RequireStderr(t, []string{"ERROR: err1"})
|
|
res.RequireStdout(t, []string{"Scaling web... "})
|
|
})
|
|
}
|
|
|
|
func TestScaleUpdateClassic(t *testing.T) {
|
|
testClientWait(t, 50*time.Millisecond, func(e *cli.Engine, i *mocksdk.Interface) {
|
|
i.On("SystemGet").Return(fxSystemClassic(), nil)
|
|
i.On("FormationUpdate", "app1", "web", structs.ServiceUpdateOptions{Count: options.Int(3), Cpu: options.Int(5), Memory: options.Int(10)}).Return(nil)
|
|
i.On("AppGet", "app1").Return(fxAppUpdating(), nil).Twice()
|
|
i.On("AppGet", "app1").Return(fxApp(), nil)
|
|
i.On("AppLogs", "app1", mock.Anything).Return(testLogs(fxLogsSystem()), nil)
|
|
|
|
res, err := testExecute(e, "scale web --cpu 5 --memory 10 --count 3 -a app1", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, res.Code)
|
|
res.RequireStderr(t, []string{""})
|
|
res.RequireStdout(t, []string{
|
|
"Scaling web... ",
|
|
"TIME system/aws/component log1",
|
|
"TIME system/aws/component log2",
|
|
"OK",
|
|
})
|
|
})
|
|
}
|