github.com/GGP1/kure@v0.8.4/commands/config/create/create_test.go (about)

     1  package create
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/GGP1/kure/config"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestCreateErrors(t *testing.T) {
    13  	cases := []struct {
    14  		desc   string
    15  		path   string
    16  		editor string
    17  	}{
    18  		{
    19  			desc: "Invalid path",
    20  			path: "",
    21  		},
    22  		{
    23  			desc:   "Executable not found",
    24  			path:   ".test.yaml",
    25  			editor: "arhoan",
    26  		},
    27  	}
    28  
    29  	cmd := NewCmd()
    30  
    31  	for _, tc := range cases {
    32  		t.Run(tc.desc, func(t *testing.T) {
    33  			config.Set("editor", tc.editor)
    34  			config.SetFilename(tc.path)
    35  
    36  			f := cmd.Flags()
    37  			f.Set("path", tc.path)
    38  
    39  			err := cmd.Execute()
    40  			assert.Error(t, err)
    41  		})
    42  	}
    43  
    44  	// Cleanup
    45  	err := os.Remove(".test.yaml")
    46  	assert.NoError(t, err, "Failed removing file")
    47  }
    48  
    49  func TestPostRun(t *testing.T) {
    50  	NewCmd().PostRun(nil, nil)
    51  }