github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/cli/edit_test.go (about) 1 package cli 2 3 import ( 4 "bytes" 5 "os" 6 "runtime" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 12 "k8s.io/cli-runtime/pkg/genericclioptions" 13 14 "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1" 15 ) 16 17 func TestEdit(t *testing.T) { 18 if runtime.GOOS == "windows" { 19 t.Skip() // 'true' is not an editor on Windows 20 } 21 22 f := newServerFixture(t) 23 24 err := f.client.Create(f.ctx, &v1alpha1.Cmd{ 25 ObjectMeta: metav1.ObjectMeta{Name: "my-sleep"}, 26 Spec: v1alpha1.CmdSpec{ 27 Args: []string{"sleep", "100"}, 28 }, 29 }) 30 require.NoError(t, err) 31 32 out := bytes.NewBuffer(nil) 33 streams := genericclioptions.IOStreams{Out: out, ErrOut: out, In: os.Stdin} 34 35 cmd := newEditCmd(streams) 36 cmd.register() 37 38 t.Setenv("EDITOR", "true") 39 err = cmd.run(f.ctx, []string{"cmd", "my-sleep"}) 40 require.NoError(t, err) 41 42 assert.Contains(t, out.String(), `Edit cancelled, no changes made`) 43 }