@@ -601,6 +601,172 @@ func TestExtensionUninstallCmd_WriteConfigError(t *testing.T) {
601601 }
602602}
603603
604+ /* ------------------------------------------------------------------------- */
605+ /* EXTENSION ENABLE COMMAND */
606+ /* ------------------------------------------------------------------------- */
607+
608+ func TestExtensionEnableCmd_Success (t * testing.T ) {
609+ tmpDir := t .TempDir ()
610+ configPath := filepath .Join (tmpDir , ".sley.yaml" )
611+
612+ content := `extensions:
613+ - name: mock-extension
614+ path: /some/path
615+ enabled: false`
616+ if err := os .WriteFile (configPath , []byte (content ), 0644 ); err != nil {
617+ t .Fatalf ("failed to write config file: %v" , err )
618+ }
619+
620+ cfg := & config.Config {Path : configPath }
621+ appCli := testutils .BuildCLIForTests (cfg .Path , []* cli.Command {Run ()})
622+
623+ output , err := testutils .CaptureStdout (func () {
624+ testutils .RunCLITest (t , appCli , []string {
625+ "sley" , "extension" , "enable" , "--name" , "mock-extension" ,
626+ }, tmpDir )
627+ })
628+ if err != nil {
629+ t .Fatalf ("CLI run failed: %v" , err )
630+ }
631+
632+ expected := `Extension "mock-extension" enabled.`
633+ if ! strings .Contains (output , expected ) {
634+ t .Errorf ("expected output to contain %q, got:\n %s" , expected , output )
635+ }
636+
637+ // Verify the extension is now enabled in the config
638+ data , readErr := os .ReadFile (configPath )
639+ if readErr != nil {
640+ t .Fatalf ("failed to read config: %v" , readErr )
641+ }
642+ if ! strings .Contains (string (data ), "enabled: true" ) {
643+ t .Errorf ("expected config to contain 'enabled: true', got:\n %s" , string (data ))
644+ }
645+ }
646+
647+ func TestExtensionEnableCmd_MissingName (t * testing.T ) {
648+ if os .Getenv ("TEST_EXTENSION_ENABLE_MISSING_NAME" ) == "1" {
649+ tmp := t .TempDir ()
650+ configPath := filepath .Join (tmp , ".sley.yaml" )
651+ content := `extensions:
652+ - name: mock-extension
653+ path: /some/path
654+ enabled: false`
655+ if err := os .WriteFile (configPath , []byte (content ), 0644 ); err != nil {
656+ fmt .Fprintln (os .Stderr , "failed to write config:" , err )
657+ os .Exit (1 )
658+ }
659+
660+ cfg := & config.Config {Path : configPath }
661+ appCli := testutils .BuildCLIForTests (cfg .Path , []* cli.Command {Run ()})
662+
663+ err := appCli .Run (context .Background (), []string {
664+ "sley" , "extension" , "enable" ,
665+ })
666+ if err != nil {
667+ fmt .Fprintln (os .Stderr , err )
668+ os .Exit (1 )
669+ }
670+ os .Exit (0 )
671+ }
672+
673+ cmd := exec .Command (os .Args [0 ], "-test.run=TestExtensionEnableCmd_MissingName" )
674+ cmd .Env = append (os .Environ (), "TEST_EXTENSION_ENABLE_MISSING_NAME=1" )
675+ output , err := cmd .CombinedOutput ()
676+
677+ if err == nil {
678+ t .Fatal ("expected non-zero exit status" )
679+ }
680+
681+ expected := "please provide an extension name to enable"
682+ if ! strings .Contains (string (output ), expected ) {
683+ t .Errorf ("expected output to contain %q, got:\n %s" , expected , output )
684+ }
685+ }
686+
687+ /* ------------------------------------------------------------------------- */
688+ /* EXTENSION DISABLE COMMAND */
689+ /* ------------------------------------------------------------------------- */
690+
691+ func TestExtensionDisableCmd_Success (t * testing.T ) {
692+ tmpDir := t .TempDir ()
693+ configPath := filepath .Join (tmpDir , ".sley.yaml" )
694+
695+ content := `extensions:
696+ - name: mock-extension
697+ path: /some/path
698+ enabled: true`
699+ if err := os .WriteFile (configPath , []byte (content ), 0644 ); err != nil {
700+ t .Fatalf ("failed to write config file: %v" , err )
701+ }
702+
703+ cfg := & config.Config {Path : configPath }
704+ appCli := testutils .BuildCLIForTests (cfg .Path , []* cli.Command {Run ()})
705+
706+ output , err := testutils .CaptureStdout (func () {
707+ testutils .RunCLITest (t , appCli , []string {
708+ "sley" , "extension" , "disable" , "--name" , "mock-extension" ,
709+ }, tmpDir )
710+ })
711+ if err != nil {
712+ t .Fatalf ("CLI run failed: %v" , err )
713+ }
714+
715+ expected := `Extension "mock-extension" disabled.`
716+ if ! strings .Contains (output , expected ) {
717+ t .Errorf ("expected output to contain %q, got:\n %s" , expected , output )
718+ }
719+
720+ // Verify the extension is now disabled in the config
721+ data , readErr := os .ReadFile (configPath )
722+ if readErr != nil {
723+ t .Fatalf ("failed to read config: %v" , readErr )
724+ }
725+ if ! strings .Contains (string (data ), "enabled: false" ) {
726+ t .Errorf ("expected config to contain 'enabled: false', got:\n %s" , string (data ))
727+ }
728+ }
729+
730+ func TestExtensionDisableCmd_MissingName (t * testing.T ) {
731+ if os .Getenv ("TEST_EXTENSION_DISABLE_MISSING_NAME" ) == "1" {
732+ tmp := t .TempDir ()
733+ configPath := filepath .Join (tmp , ".sley.yaml" )
734+ content := `extensions:
735+ - name: mock-extension
736+ path: /some/path
737+ enabled: true`
738+ if err := os .WriteFile (configPath , []byte (content ), 0644 ); err != nil {
739+ fmt .Fprintln (os .Stderr , "failed to write config:" , err )
740+ os .Exit (1 )
741+ }
742+
743+ cfg := & config.Config {Path : configPath }
744+ appCli := testutils .BuildCLIForTests (cfg .Path , []* cli.Command {Run ()})
745+
746+ err := appCli .Run (context .Background (), []string {
747+ "sley" , "extension" , "disable" ,
748+ })
749+ if err != nil {
750+ fmt .Fprintln (os .Stderr , err )
751+ os .Exit (1 )
752+ }
753+ os .Exit (0 )
754+ }
755+
756+ cmd := exec .Command (os .Args [0 ], "-test.run=TestExtensionDisableCmd_MissingName" )
757+ cmd .Env = append (os .Environ (), "TEST_EXTENSION_DISABLE_MISSING_NAME=1" )
758+ output , err := cmd .CombinedOutput ()
759+
760+ if err == nil {
761+ t .Fatal ("expected non-zero exit status" )
762+ }
763+
764+ expected := "please provide an extension name to disable"
765+ if ! strings .Contains (string (output ), expected ) {
766+ t .Errorf ("expected output to contain %q, got:\n %s" , expected , output )
767+ }
768+ }
769+
604770/* ------------------------------------------------------------------------- */
605771/* EXTENSION INSTALL COMMAND - ADDITIONAL TESTS */
606772/* ------------------------------------------------------------------------- */
0 commit comments