update tests

This commit is contained in:
David Dollar 2019-11-05 14:33:10 -05:00
parent 36d8546167
commit c1fad03035
No known key found for this signature in database
GPG Key ID: AFAF263FB45B2124
13 changed files with 102 additions and 290 deletions

View File

@ -1,4 +1,4 @@
name: push
name: release
on:
push:
branches:

13
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: release
on:
push:
branches: ["*"]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v1
- name: test
run: make test

1
.gitignore vendored
View File

@ -1 +1,2 @@
.terraform
coverage.txt

View File

@ -6,9 +6,9 @@ import (
"net/http/httptest"
"testing"
"github.com/convox/logger"
"github.com/convox/convox/pkg/api"
"github.com/convox/convox/pkg/structs"
"github.com/convox/logger"
"github.com/convox/stdsdk"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
@ -17,6 +17,7 @@ import (
func testServer(t *testing.T, fn func(*stdsdk.Client, *structs.MockProvider)) {
p := &structs.MockProvider{}
p.On("Initialize", mock.Anything).Return(nil)
p.On("Start").Return(nil)
p.On("WithContext", mock.Anything).Return(p).Maybe()
s := api.NewWithProvider(p)

View File

@ -5,10 +5,10 @@ import (
"net/url"
"testing"
"github.com/convox/logger"
"github.com/convox/convox/pkg/api"
"github.com/convox/convox/pkg/structs"
"github.com/convox/convox/sdk"
"github.com/convox/logger"
"github.com/convox/stdsdk"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
@ -17,6 +17,7 @@ import (
func TestAuthentication(t *testing.T) {
p := &structs.MockProvider{}
p.On("Initialize", mock.Anything).Return(nil)
p.On("Start").Return(nil)
s := api.NewWithProvider(p)
s.Logger = logger.Discard

View File

@ -2,12 +2,6 @@ package cli_test
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"path/filepath"
"testing"
"time"
@ -15,8 +9,6 @@ import (
mocksdk "github.com/convox/convox/pkg/mock/sdk"
"github.com/convox/convox/pkg/options"
"github.com/convox/convox/pkg/structs"
"github.com/convox/convox/provider"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
@ -71,65 +63,6 @@ func TestRackInternal(t *testing.T) {
})
}
func TestRackInstall(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/auth", r.URL.Path)
user, pass, _ := r.BasicAuth()
require.Equal(t, "convox", user)
require.Equal(t, "password", pass)
}))
tsu, err := url.Parse(ts.URL)
require.NoError(t, err)
opts := structs.SystemInstallOptions{
Name: options.String("foo"),
Parameters: map[string]string{},
Version: options.String("bar"),
}
provider.Mock.On("SystemInstall", mock.Anything, opts).Once().Return(fmt.Sprintf("https://convox:password@%s", tsu.Host), nil).Run(func(args mock.Arguments) {
w := args.Get(0).(io.Writer)
fmt.Fprintf(w, "line1\n")
fmt.Fprintf(w, "line2\n")
})
res, err := testExecute(e, "rack install test -n foo -v bar", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
res.RequireStderr(t, []string{""})
res.RequireStdout(t, []string{
"line1",
"line2",
})
data, err := ioutil.ReadFile(filepath.Join(e.Settings, "auth"))
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("{\n \"%s\": \"password\"\n}", tsu.Host), string(data))
data, err = ioutil.ReadFile(filepath.Join(e.Settings, "host"))
require.NoError(t, err)
require.Equal(t, tsu.Host, string(data))
})
}
func TestRackInstallError(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
opts := structs.SystemInstallOptions{
Name: options.String("foo"),
Parameters: map[string]string{},
Version: options.String("bar"),
}
provider.Mock.On("SystemInstall", mock.Anything, opts).Return("", fmt.Errorf("err1"))
res, err := testExecute(e, "rack install test -n foo -v bar", nil)
require.NoError(t, err)
require.Equal(t, 1, res.Code)
res.RequireStderr(t, []string{"ERROR: err1"})
res.RequireStdout(t, []string{""})
})
}
func TestRackLogs(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
i.On("SystemLogs", structs.LogsOptions{Prefix: options.Bool(true)}).Return(testLogs(fxLogs()), nil)
@ -376,53 +309,6 @@ func TestRackScaleUpdateError(t *testing.T) {
})
}
func TestRackUninstall(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
opts := structs.SystemUninstallOptions{
Force: options.Bool(true),
}
provider.Mock.On("SystemUninstall", "foo", mock.Anything, opts).Once().Return(nil).Run(func(args mock.Arguments) {
w := args.Get(1).(io.Writer)
fmt.Fprintf(w, "line1\n")
fmt.Fprintf(w, "line2\n")
})
res, err := testExecute(e, "rack uninstall test foo --force", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
res.RequireStderr(t, []string{""})
res.RequireStdout(t, []string{
"line1",
"line2",
})
})
}
func TestRackUninstallError(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
opts := structs.SystemUninstallOptions{
Force: options.Bool(true),
}
provider.Mock.On("SystemUninstall", "foo", mock.Anything, opts).Return(fmt.Errorf("err1"))
res, err := testExecute(e, "rack uninstall test foo --force", nil)
require.NoError(t, err)
require.Equal(t, 1, res.Code)
res.RequireStderr(t, []string{"ERROR: err1"})
res.RequireStdout(t, []string{""})
})
}
func TestRackUninstallWithoutForce(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
res, err := testExecute(e, "rack uninstall test foo", nil)
require.NoError(t, err)
require.Equal(t, 1, res.Code)
res.RequireStderr(t, []string{"ERROR: must use --force for non-interactive uninstall"})
res.RequireStdout(t, []string{""})
})
}
func TestRackUpdate(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
i.On("SystemUpdate", structs.SystemUpdateOptions{Version: options.String("version1")}).Return(nil)

View File

@ -6,10 +6,8 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"github.com/convox/convox/pkg/start"
"github.com/convox/convox/pkg/structs"
"github.com/convox/convox/sdk"
"github.com/convox/stdcli"
)
@ -39,50 +37,44 @@ func Start(rack sdk.Interface, c *stdcli.Context) error {
return fmt.Errorf("gen1 is no longer supported")
}
var p structs.Provider
// var p structs.Provider
if rack != nil {
p = rack
// s, err := rack.SystemGet()
// if err != nil {
// return err
// }
// if s.Provider == "local" || s.Provider == "kaws" {
// p = rack
// }
}
// if rack != nil {
// fmt.Printf("rack: %+v\n", rack)
// p = rack
// }
if p == nil {
if !localRackRunning(c) {
return fmt.Errorf("local rack not found, try `sudo convox rack install local`")
}
// if p == nil {
// if !localRackRunning(c) {
// return fmt.Errorf("local rack not found, try `sudo convox rack install local`")
// }
r, err := matchRack(c, "local/")
if err != nil {
if strings.HasPrefix(err.Error(), "ambiguous rack name") {
return fmt.Errorf("multiple local racks detected, use `convox switch` to select one")
}
return err
}
// r, err := matchRack(c, "local/")
// if err != nil {
// if strings.HasPrefix(err.Error(), "ambiguous rack name") {
// return fmt.Errorf("multiple local racks detected, use `convox switch` to select one")
// }
// return err
// }
cl, err := sdk.New(fmt.Sprintf("https://rack.%s", strings.TrimPrefix(r.Name, "local/")))
if err != nil {
return err
}
// cl, err := sdk.New(fmt.Sprintf("https://rack.%s", strings.TrimPrefix(r.Name, "local/")))
// if err != nil {
// return err
// }
p = cl
}
// p = cl
// }
if p == nil {
return fmt.Errorf("could not find local rack")
}
// if p == nil {
// return fmt.Errorf("could not find local rack")
// }
opts := start.Options2{
App: app(c),
Build: !c.Bool("no-build"),
Cache: !c.Bool("no-cache"),
Manifest: c.String("manifest"),
Provider: p,
Provider: rack,
Sync: !c.Bool("no-sync"),
}

View File

@ -9,81 +9,10 @@ import (
mockstart "github.com/convox/convox/pkg/mock/start"
mockstdcli "github.com/convox/convox/pkg/mock/stdcli"
"github.com/convox/convox/pkg/start"
"github.com/convox/convox/sdk"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestStart1(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
ms := &mockstart.Interface{}
cli.Starter = ms
opts := start.Options1{
App: "app1",
Build: true,
Cache: true,
Sync: true,
}
ms.On("Start1", mock.Anything, opts).Return(nil)
res, err := testExecute(e, "start -g 1 -a app1", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
res.RequireStderr(t, []string{""})
res.RequireStdout(t, []string{""})
})
}
func TestStart1Error(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
ms := &mockstart.Interface{}
cli.Starter = ms
opts := start.Options1{
App: "app1",
Build: true,
Cache: true,
Sync: true,
}
ms.On("Start1", mock.Anything, opts).Return(fmt.Errorf("err1"))
res, err := testExecute(e, "start -g 1 -a app1", nil)
require.NoError(t, err)
require.Equal(t, 1, res.Code)
res.RequireStderr(t, []string{"ERROR: err1"})
res.RequireStdout(t, []string{""})
})
}
func TestStart1Options(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
ms := &mockstart.Interface{}
cli.Starter = ms
opts := start.Options1{
App: "app1",
Build: false,
Cache: false,
Command: []string{"bin/command", "args"},
Manifest: "manifest1",
Service: "service1",
Shift: 3000,
Sync: false,
}
ms.On("Start1", mock.Anything, opts).Return(nil)
res, err := testExecute(e, "start -g 1 -a app1 -m manifest1 --no-build --no-cache --no-sync -s 3000 service1 bin/command args", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
res.RequireStderr(t, []string{""})
res.RequireStdout(t, []string{""})
})
}
func TestStart2(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
me := &mockstdcli.Executor{}
@ -103,8 +32,6 @@ func TestStart2(t *testing.T) {
ms.On("Start2", mock.Anything, mock.Anything, opts).Return(nil)
i.On("SystemGet").Return(fxSystemLocal, nil)
res, err := testExecute(e, "start -g 2 -a app1", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
@ -132,8 +59,6 @@ func TestStart2Error(t *testing.T) {
ms.On("Start2", mock.Anything, mock.Anything, opts).Return(fmt.Errorf("err1"))
i.On("SystemGet").Return(fxSystemLocal, nil)
res, err := testExecute(e, "start -g 2 -a app1", nil)
require.NoError(t, err)
require.Equal(t, 1, res.Code)
@ -163,8 +88,6 @@ func TestStart2Options(t *testing.T) {
ms.On("Start2", mock.Anything, mock.Anything, opts).Return(nil)
i.On("SystemGet").Return(fxSystemLocal(), nil)
res, err := testExecute(e, "start -g 2 -a app1 -m manifest1 --no-build --no-cache --no-sync service1 service2", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
@ -173,64 +96,61 @@ func TestStart2Options(t *testing.T) {
})
}
func TestStart2Remote(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
me := &mockstdcli.Executor{}
me.On("Execute", "kubectl", "get", "ns", "--selector=system=convox,type=rack", "--output=name").Return([]byte("namespace/dev"), nil)
e.Executor = me
// func TestStart2Remote(t *testing.T) {
// testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
// me := &mockstdcli.Executor{}
// me.On("Execute", "kubectl", "get", "ns", "--selector=system=convox,type=rack", "--output=name").Return([]byte("namespace/dev"), nil)
// e.Executor = me
ms := &mockstart.Interface{}
cli.Starter = ms
// ms := &mockstart.Interface{}
// cli.Starter = ms
ms.On("Start2", mock.Anything, mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
opts := args.Get(2).(start.Options2)
require.Equal(t, "app1", opts.App)
require.Equal(t, true, opts.Build)
require.Equal(t, true, opts.Cache)
require.Equal(t, true, opts.Sync)
p := opts.Provider.(*sdk.Client)
require.Equal(t, "https", p.Client.Endpoint.Scheme)
require.Equal(t, "rack.dev", p.Client.Endpoint.Host)
})
// ms.On("Start2", mock.Anything, mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
// opts := args.Get(2).(start.Options2)
// require.Equal(t, "app1", opts.App)
// require.Equal(t, true, opts.Build)
// require.Equal(t, true, opts.Cache)
// require.Equal(t, true, opts.Sync)
// fmt.Printf("opts.Provider: %+v\n", opts.Provider)
// p := opts.Provider.(*sdk.Client)
// require.Equal(t, "https", p.Client.Endpoint.Scheme)
// require.Equal(t, "rack.dev", p.Client.Endpoint.Host)
// })
i.On("SystemGet").Return(fxSystem(), nil)
// res, err := testExecute(e, "start -g 2 -a app1", nil)
// require.NoError(t, err)
// require.Equal(t, 0, res.Code)
// res.RequireStderr(t, []string{""})
// res.RequireStdout(t, []string{""})
// })
// }
res, err := testExecute(e, "start -g 2 -a app1", nil)
require.NoError(t, err)
require.Equal(t, 0, res.Code)
res.RequireStderr(t, []string{""})
res.RequireStdout(t, []string{""})
})
}
// func TestStart2RemoteMultiple(t *testing.T) {
// testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
// me := &mockstdcli.Executor{}
// me.On("Execute", "kubectl", "get", "ns", "--selector=system=convox,type=rack", "--output=name").Return([]byte("namespace/dev\nnamespace/dev2\n"), nil)
// e.Executor = me
func TestStart2RemoteMultiple(t *testing.T) {
testClient(t, func(e *cli.Engine, i *mocksdk.Interface) {
me := &mockstdcli.Executor{}
me.On("Execute", "kubectl", "get", "ns", "--selector=system=convox,type=rack", "--output=name").Return([]byte("namespace/dev\nnamespace/dev2\n"), nil)
e.Executor = me
// ms := &mockstart.Interface{}
// cli.Starter = ms
ms := &mockstart.Interface{}
cli.Starter = ms
// opts := start.Options2{
// App: "app1",
// Build: true,
// Cache: true,
// Sync: true,
// }
opts := start.Options2{
App: "app1",
Build: true,
Cache: true,
Sync: true,
}
// ms.On("Start2", mock.Anything, opts).Return(nil).Run(func(args mock.Arguments) {
// s := args.Get(0).(*sdk.Client)
// require.Equal(t, "https", s.Client.Endpoint.Scheme)
// require.Equal(t, "rack.classic", s.Client.Endpoint.Host)
// })
ms.On("Start2", mock.Anything, opts).Return(nil).Run(func(args mock.Arguments) {
s := args.Get(0).(*sdk.Client)
require.Equal(t, "https", s.Client.Endpoint.Scheme)
require.Equal(t, "rack.classic", s.Client.Endpoint.Host)
})
i.On("SystemGet").Return(fxSystem(), nil)
res, err := testExecute(e, "start -g 2 -a app1", nil)
require.NoError(t, err)
require.Equal(t, 1, res.Code)
res.RequireStderr(t, []string{"ERROR: multiple local racks detected, use `convox switch` to select one"})
res.RequireStdout(t, []string{""})
})
}
// res, err := testExecute(e, "start -g 2 -a app1", nil)
// require.NoError(t, err)
// require.Equal(t, 1, res.Code)
// res.RequireStderr(t, []string{"ERROR: multiple local racks detected, use `convox switch` to select one"})
// res.RequireStdout(t, []string{""})
// })
// }

View File

@ -9,11 +9,11 @@ import (
"testing"
"time"
"github.com/convox/exec"
"github.com/convox/convox/pkg/common"
"github.com/convox/convox/pkg/options"
"github.com/convox/convox/pkg/start"
"github.com/convox/convox/pkg/structs"
"github.com/convox/exec"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
@ -74,7 +74,7 @@ func TestStart2(t *testing.T) {
}
func TestStart2Options(t *testing.T) {
helpers.ProviderWaitDuration = 1
common.ProviderWaitDuration = 1
p := &structs.MockProvider{}

View File

@ -83,7 +83,7 @@ func TestAppCreate(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, a)
assert.Equal(t, "2", a.Generation)
assert.Equal(t, "3", a.Generation)
assert.Equal(t, "app1", a.Name)
})
}
@ -124,7 +124,7 @@ func TestAppGet(t *testing.T) {
a, err := p.AppGet("app1")
require.NoError(t, err)
assert.Equal(t, "2", a.Generation)
assert.Equal(t, "3", a.Generation)
assert.Equal(t, false, a.Locked)
assert.Equal(t, "app1", a.Name)
assert.Equal(t, "R1234567", a.Release)
@ -174,17 +174,18 @@ func TestAppList(t *testing.T) {
require.NoError(t, appCreate(kk, "rack1", "app2"))
as, err := p.AppList()
fmt.Printf("as: %+v\n", as)
require.NoError(t, err)
require.Equal(t, 2, len(as))
assert.Equal(t, "2", as[0].Generation)
assert.Equal(t, "3", as[0].Generation)
assert.Equal(t, false, as[0].Locked)
assert.Equal(t, "app1", as[0].Name)
assert.Equal(t, "R1234567", as[0].Release)
assert.Equal(t, "", as[0].Router)
assert.Equal(t, "running", as[0].Status)
assert.Equal(t, "2", as[1].Generation)
assert.Equal(t, "3", as[1].Generation)
assert.Equal(t, false, as[1].Locked)
assert.Equal(t, "app2", as[1].Name)
assert.Equal(t, "R2345678", as[1].Release)

View File

@ -30,6 +30,5 @@ spec:
- from:
- namespaceSelector:
matchLabels:
scope: system
system: convox
podSelector: {}

View File

@ -30,6 +30,5 @@ spec:
- from:
- namespaceSelector:
matchLabels:
scope: system
system: convox
podSelector: {}

View File

@ -30,6 +30,5 @@ spec:
- from:
- namespaceSelector:
matchLabels:
scope: system
system: convox
podSelector: {}