44 "bytes"
55 "context"
66 "errors"
7+ "os"
78 "path/filepath"
89 "strings"
910 "testing"
@@ -219,7 +220,7 @@ func TestSelfCmd(t *testing.T) {
219220 t .Run ("should use help func when run without args" , func (t * testing.T ) {
220221 rootCmd := CreateRootCommand ("v0.0.0-test" , "" )
221222 rootCmd .SetArgs ([]string {"self" })
222- initSelfCmd (rootCmd , "v0.0.0-test" , func (string ) error { return nil })
223+ initSelfCmd (rootCmd , "v0.0.0-test" , func (string ) error { return nil }, func ( string ) error { return nil } )
223224
224225 called := false
225226 rootCmd .SetHelpFunc (func (c * cobra.Command , args []string ) {
@@ -246,7 +247,7 @@ func TestSelfCmd(t *testing.T) {
246247 rootCmd .SetArgs ([]string {"self" , "config" , "path" })
247248 rootCmd .SetOut (bufOut )
248249 rootCmd .SetErr (bufOut )
249- initSelfCmd (rootCmd , "v0.0.0-test" , func (string ) error { return nil })
250+ initSelfCmd (rootCmd , "v0.0.0-test" , func (string ) error { return nil }, func ( string ) error { return nil } )
250251
251252 if err := rootCmd .Execute (); err != nil {
252253 t .Fatalf ("unexpected error: %v" , err )
@@ -269,7 +270,7 @@ func TestSelfCmd(t *testing.T) {
269270 rootCmd .SetArgs ([]string {"self" , "config" , "edit" })
270271 rootCmd .SetOut (bufOut )
271272 rootCmd .SetErr (bufOut )
272- initSelfCmdWithEditor (rootCmd , "v0.0.0-test" , func (string ) error { return nil }, func (path string ) error {
273+ initSelfCmd (rootCmd , "v0.0.0-test" , func (string ) error { return nil }, func (path string ) error {
273274 called = true
274275 gotPath = path
275276
@@ -288,6 +289,15 @@ func TestSelfCmd(t *testing.T) {
288289 if gotPath != expected {
289290 t .Fatalf ("expected editor path %q, got %q" , expected , gotPath )
290291 }
292+
293+ info , err := os .Stat (filepath .Dir (expected ))
294+ if err != nil {
295+ t .Fatalf ("expected config directory to exist: %v" , err )
296+ }
297+
298+ if perm := info .Mode ().Perm (); perm != 0o700 {
299+ t .Fatalf ("expected config directory permissions 0700, got %o" , perm )
300+ }
291301 })
292302
293303 t .Run ("should open documentation in browser" , func (t * testing.T ) {
@@ -306,7 +316,7 @@ func TestSelfCmd(t *testing.T) {
306316 rootCmd .SetArgs ([]string {"self" , "doc" })
307317 rootCmd .SetOut (bufOut )
308318 rootCmd .SetErr (bufOut )
309- initSelfCmd (rootCmd , "v0.0.0-test" , openURL )
319+ initSelfCmd (rootCmd , "v0.0.0-test" , openURL , func ( string ) error { return nil } )
310320
311321 err := rootCmd .Execute ()
312322 if err != nil {
@@ -333,7 +343,7 @@ func TestSelfCmd(t *testing.T) {
333343 rootCmd .SetArgs ([]string {"self" , "doc" })
334344 rootCmd .SetOut (bufOut )
335345 rootCmd .SetErr (bufOut )
336- initSelfCmd (rootCmd , "v0.0.0-test" , openURL )
346+ initSelfCmd (rootCmd , "v0.0.0-test" , openURL , func ( string ) error { return nil } )
337347
338348 err := rootCmd .Execute ()
339349 if err == nil {
0 commit comments