2020-08-06 20:58:47 +03:00
|
|
|
package cli_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/cli/testrun"
|
2020-08-06 20:58:47 +03:00
|
|
|
"github.com/neilotoole/sq/testh"
|
|
|
|
"github.com/neilotoole/sq/testh/sakila"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCmdRemove(t *testing.T) {
|
|
|
|
th := testh.New(t)
|
|
|
|
|
|
|
|
// 1. Should fail if bad handle
|
2023-05-19 17:24:18 +03:00
|
|
|
tr := testrun.New(th.Context, t, nil)
|
|
|
|
err := tr.Exec("rm", "@not_a_source")
|
2020-08-06 20:58:47 +03:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
// 2. Check normal operation
|
|
|
|
src := th.Source(sakila.SL3)
|
2023-05-19 17:24:18 +03:00
|
|
|
tr = testrun.New(th.Context, t, nil).Add(*src)
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
// The src we just added should be the active src
|
2023-05-19 17:24:18 +03:00
|
|
|
activeSrc := tr.Run.Config.Collection.Active()
|
2020-08-06 20:58:47 +03:00
|
|
|
require.NotNil(t, activeSrc)
|
|
|
|
require.Equal(t, src.Handle, activeSrc.Handle)
|
|
|
|
|
2023-05-19 17:24:18 +03:00
|
|
|
err = tr.Exec("rm", src.Handle)
|
2020-08-06 20:58:47 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-05-19 17:24:18 +03:00
|
|
|
activeSrc = tr.Run.Config.Collection.Active()
|
2020-08-06 20:58:47 +03:00
|
|
|
require.Nil(t, activeSrc, "should be no active src anymore")
|
|
|
|
}
|