@@ -712,6 +712,91 @@ func TestIsTagManagerEnabled(t *testing.T) {
712712 }
713713}
714714
715+ func TestRequireTagManagerEnabled (t * testing.T ) {
716+ tests := []struct {
717+ name string
718+ cfg * config.Config
719+ wantErr bool
720+ }{
721+ {
722+ name : "nil config" ,
723+ cfg : nil ,
724+ wantErr : true ,
725+ },
726+ {
727+ name : "nil plugins" ,
728+ cfg : & config.Config {},
729+ wantErr : true ,
730+ },
731+ {
732+ name : "disabled" ,
733+ cfg : & config.Config {
734+ Plugins : & config.PluginConfig {
735+ TagManager : & config.TagManagerConfig {Enabled : false },
736+ },
737+ },
738+ wantErr : true ,
739+ },
740+ {
741+ name : "enabled" ,
742+ cfg : & config.Config {
743+ Plugins : & config.PluginConfig {
744+ TagManager : & config.TagManagerConfig {Enabled : true },
745+ },
746+ },
747+ wantErr : false ,
748+ },
749+ }
750+
751+ for _ , tt := range tests {
752+ t .Run (tt .name , func (t * testing.T ) {
753+ _ , err := requireTagManagerEnabled (tt .cfg )
754+ if (err != nil ) != tt .wantErr {
755+ t .Errorf ("requireTagManagerEnabled() error = %v, wantErr %v" , err , tt .wantErr )
756+ }
757+ if tt .wantErr && err != nil {
758+ if ! strings .Contains (err .Error (), "tag-manager plugin is not enabled" ) {
759+ t .Errorf ("requireTagManagerEnabled() error message = %q, want it to contain 'tag-manager plugin is not enabled'" , err .Error ())
760+ }
761+ }
762+ })
763+ }
764+ }
765+
766+ func TestTagCommand_BeforeHookBlocksSubcommands (t * testing.T ) {
767+ // Verify that running any tag subcommand via Run() fails when plugin is disabled.
768+ cfg := & config.Config {
769+ Path : ".version" ,
770+ // No tag-manager plugin configured.
771+ }
772+
773+ app := & cli.Command {
774+ Name : "sley" ,
775+ Writer : io .Discard ,
776+ ErrWriter : io .Discard ,
777+ Commands : []* cli.Command {Run (cfg )},
778+ }
779+
780+ subcommands := [][]string {
781+ {"sley" , "tag" , "list" },
782+ {"sley" , "tag" , "create" },
783+ {"sley" , "tag" , "push" , "v1.0.0" },
784+ {"sley" , "tag" , "delete" , "v1.0.0" },
785+ }
786+
787+ for _ , args := range subcommands {
788+ t .Run (strings .Join (args [1 :], " " ), func (t * testing.T ) {
789+ err := app .Run (context .Background (), args )
790+ if err == nil {
791+ t .Errorf ("expected error for %v when tag-manager is not enabled" , args )
792+ }
793+ if err != nil && ! strings .Contains (err .Error (), "tag-manager plugin is not enabled" ) {
794+ t .Errorf ("unexpected error for %v: %v" , args , err )
795+ }
796+ })
797+ }
798+ }
799+
715800func TestRunCommand (t * testing.T ) {
716801 cfg := & config.Config {
717802 Path : ".version" ,
@@ -1530,6 +1615,11 @@ func TestCLI_TagCreate_MultiModule(t *testing.T) {
15301615 maxDepth := 10
15311616 cfg := & config.Config {
15321617 Path : ".version" ,
1618+ Plugins : & config.PluginConfig {
1619+ TagManager : & config.TagManagerConfig {
1620+ Enabled : true ,
1621+ },
1622+ },
15331623 Workspace : & config.WorkspaceConfig {
15341624 Discovery : & config.DiscoveryConfig {
15351625 Enabled : & enabled ,
@@ -1612,6 +1702,11 @@ func TestCLI_TagPush_MultiModule_NoArg(t *testing.T) {
16121702 maxDepth := 10
16131703 cfg := & config.Config {
16141704 Path : ".version" ,
1705+ Plugins : & config.PluginConfig {
1706+ TagManager : & config.TagManagerConfig {
1707+ Enabled : true ,
1708+ },
1709+ },
16151710 Workspace : & config.WorkspaceConfig {
16161711 Discovery : & config.DiscoveryConfig {
16171712 Enabled : & enabled ,
0 commit comments