diff --git a/cmd/aclsetup.go b/cmd/aclsetup.go index 0027c10..1a89076 100644 --- a/cmd/aclsetup.go +++ b/cmd/aclsetup.go @@ -16,7 +16,6 @@ func NewAclSetupCmd() *cobra.Command { Use: "aclsetup", Short: "Adjust the access control list", Long: "Configures users/groups to run the Cobbler CLI as non-root.", - Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { err := generateCobblerClient() if err != nil { @@ -56,5 +55,7 @@ func NewAclSetupCmd() *cobra.Command { aclsetupCmd.Flags().String("addgroup", "", "give acls to this group") aclsetupCmd.Flags().String("removeuser", "", "remove acls from this user") aclsetupCmd.Flags().String("removegroup", "", "remove acls from this user") + aclsetupCmd.MarkFlagsMutuallyExclusive("adduser", "addgroup", "removeuser", "removegroup") + aclsetupCmd.MarkFlagsOneRequired("adduser", "addgroup", "removeuser", "removegroup") return aclsetupCmd } diff --git a/cmd/aclsetup_test.go b/cmd/aclsetup_test.go index ac30c98..6764be0 100644 --- a/cmd/aclsetup_test.go +++ b/cmd/aclsetup_test.go @@ -1,14 +1,21 @@ package cmd import ( + "bytes" "github.com/cobbler/cobblerclient" + "github.com/spf13/cobra" "testing" ) func Test_AclSetupCommand_Adduser(t *testing.T) { // Arrange + cobra.OnInitialize(initConfig, setupLogger) rootCmd := NewRootCmd() - rootCmd.SetArgs([]string{"aclsetup", "--adduser", "cobbler"}) + rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "aclsetup", "--adduser", "cobbler"}) + stdout := bytes.NewBufferString("") + stderr := bytes.NewBufferString("") + rootCmd.SetOut(stdout) + rootCmd.SetErr(stderr) // Act err := rootCmd.Execute() @@ -20,8 +27,13 @@ func Test_AclSetupCommand_Adduser(t *testing.T) { func Test_AclSetupCommand_Addgroup(t *testing.T) { // Arrange + cobra.OnInitialize(initConfig, setupLogger) rootCmd := NewRootCmd() - rootCmd.SetArgs([]string{"aclsetup", "--addgroup", "cobbler"}) + rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "aclsetup", "--addgroup", "cobbler"}) + stdout := bytes.NewBufferString("") + stderr := bytes.NewBufferString("") + rootCmd.SetOut(stdout) + rootCmd.SetErr(stderr) // Act err := rootCmd.Execute() @@ -33,8 +45,13 @@ func Test_AclSetupCommand_Addgroup(t *testing.T) { func Test_AclSetupCommand_Removeuser(t *testing.T) { // Arrange + cobra.OnInitialize(initConfig, setupLogger) rootCmd := NewRootCmd() - rootCmd.SetArgs([]string{"aclsetup", "--removeuser", "cobbler"}) + rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "aclsetup", "--removeuser", "cobbler"}) + stdout := bytes.NewBufferString("") + stderr := bytes.NewBufferString("") + rootCmd.SetOut(stdout) + rootCmd.SetErr(stderr) // Act err := rootCmd.Execute() @@ -46,8 +63,13 @@ func Test_AclSetupCommand_Removeuser(t *testing.T) { func Test_AclSetupCommand_Removegroup(t *testing.T) { // Arrange + cobra.OnInitialize(initConfig, setupLogger) rootCmd := NewRootCmd() - rootCmd.SetArgs([]string{"aclsetup", "--removegroup", "cobbler"}) + rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "aclsetup", "--removegroup", "cobbler"}) + stdout := bytes.NewBufferString("") + stderr := bytes.NewBufferString("") + rootCmd.SetOut(stdout) + rootCmd.SetErr(stderr) // Act err := rootCmd.Execute() diff --git a/cmd/version_test.go b/cmd/version_test.go index 97beef2..4b231a5 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -3,13 +3,15 @@ package cmd import ( "bytes" "github.com/cobbler/cobblerclient" + "github.com/spf13/cobra" "testing" ) func Test_VersionCommand(t *testing.T) { // Arrange + cobra.OnInitialize(initConfig, setupLogger) rootCmd := NewRootCmd() - rootCmd.SetArgs([]string{"--config", "testing/.cobbler.yaml", "version"}) + rootCmd.SetArgs([]string{"--config", "../testing/.cobbler.yaml", "version"}) stdout := bytes.NewBufferString("") stderr := bytes.NewBufferString("") rootCmd.SetOut(stdout)