Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolGuy committed Oct 30, 2024
1 parent e966aff commit a9f5fe5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/aclsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
30 changes: 26 additions & 4 deletions cmd/aclsetup_test.go
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a9f5fe5

Please sign in to comment.