@@ -65,20 +65,20 @@ func TestShouldCheckForUpdate(t *testing.T) {
6565 t .Run ("should allow normal interactive commands" , func (t * testing.T ) {
6666 t .Setenv ("CI" , "" )
6767
68- if ! shouldCheckForUpdate ("lets" , true , defaultSettings ) {
68+ if ! shouldCheckForUpdate (& cobra. Command { Use : "run" } , true , defaultSettings ) {
6969 t .Fatal ("expected update check to be enabled" )
7070 }
7171 })
7272
7373 t .Run ("should skip non interactive sessions" , func (t * testing.T ) {
74- if shouldCheckForUpdate ("lets" , false , defaultSettings ) {
74+ if shouldCheckForUpdate (& cobra. Command { Use : "run" } , false , defaultSettings ) {
7575 t .Fatal ("expected non-interactive session to skip update check" )
7676 }
7777 })
7878
7979 t .Run ("should skip when CI is set" , func (t * testing.T ) {
8080 t .Setenv ("CI" , "1" )
81- if shouldCheckForUpdate ("lets" , true , defaultSettings ) {
81+ if shouldCheckForUpdate (& cobra. Command { Use : "run" } , true , defaultSettings ) {
8282 t .Fatal ("expected CI to skip update check" )
8383 }
8484 })
@@ -87,16 +87,45 @@ func TestShouldCheckForUpdate(t *testing.T) {
8787 disabled := settings .Default ()
8888 disabled .UpgradeNotify = false
8989
90- if shouldCheckForUpdate ("lets" , true , disabled ) {
90+ if shouldCheckForUpdate (& cobra. Command { Use : "run" } , true , disabled ) {
9191 t .Fatal ("expected disabled settings to skip update check" )
9292 }
9393 })
9494
95- t .Run ("should skip internal commands" , func (t * testing.T ) {
96- for _ , name := range []string { "completion" , "help" , "lsp" , "self" } {
97- if shouldCheckForUpdate (name , true , defaultSettings ) {
98- t .Fatalf ("expected %q to skip update check" , name )
95+ t .Run ("should skip completion and help commands" , func (t * testing.T ) {
96+ for _ , command := range []* cobra. Command {{ Use : "completion" }, { Use : "help" } } {
97+ if shouldCheckForUpdate (command , true , defaultSettings ) {
98+ t .Fatalf ("expected %q to skip update check" , command . Name () )
9999 }
100100 }
101101 })
102+
103+ t .Run ("should skip self subcommands" , func (t * testing.T ) {
104+ root := cmdpkg .CreateRootCommand ("v0.0.0-test" , "" )
105+ cmdpkg .InitSelfCmd (root , "v0.0.0-test" )
106+
107+ for _ , args := range [][]string {{"self" }, {"self" , "doc" }, {"self" , "upgrade" }} {
108+ command , _ , err := root .Find (args )
109+ if err != nil {
110+ t .Fatalf ("unexpected error for %v: %v" , args , err )
111+ }
112+
113+ if shouldCheckForUpdate (command , true , defaultSettings ) {
114+ t .Fatalf ("expected %v to skip update check" , args )
115+ }
116+ }
117+ })
118+ }
119+
120+ func TestParseRootFlags (t * testing.T ) {
121+ t .Run ("should reject legacy upgrade flag" , func (t * testing.T ) {
122+ _ , err := parseRootFlags ([]string {"--upgrade" })
123+ if err == nil {
124+ t .Fatal ("expected legacy upgrade flag error" )
125+ }
126+
127+ if err .Error () != "--upgrade has been replaced with 'lets self upgrade'" {
128+ t .Fatalf ("unexpected error: %v" , err )
129+ }
130+ })
102131}
0 commit comments