Add container rename support
Signed-off-by: jason yang <jasonyangshadow@gmail.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
7d17bcc6fa
commit
d262ec10ef
63
internal/app/wwctl/container/rename/main_test.go
Normal file
63
internal/app/wwctl/container/rename/main_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package rename
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
containerList "github.com/hpcng/warewulf/internal/app/wwctl/container/list"
|
||||
"github.com/hpcng/warewulf/internal/pkg/testenv"
|
||||
"github.com/hpcng/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Rename(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, path.Join(testenv.WWChrootdir, "test-container/rootfs/file"), `test`)
|
||||
defer env.RemoveAll(t)
|
||||
warewulfd.SetNoDaemon()
|
||||
|
||||
// first we will verify that there is an existing container
|
||||
t.Run("container list", func(t *testing.T) {
|
||||
verifyContainerListOutput(t, "test-container")
|
||||
})
|
||||
|
||||
// then rename it
|
||||
t.Run("container rename", func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetOut(nil)
|
||||
baseCmd.SetErr(nil)
|
||||
baseCmd.SetArgs([]string{"test-container", "test-container-rename"})
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
// retrieve again
|
||||
t.Run("Container list", func(t *testing.T) {
|
||||
verifyContainerListOutput(t, "test-container-rename")
|
||||
})
|
||||
}
|
||||
|
||||
func verifyContainerListOutput(t *testing.T, content string) {
|
||||
baseCmd := containerList.GetCommand()
|
||||
baseCmd.SetOut(nil)
|
||||
baseCmd.SetErr(nil)
|
||||
stdoutR, stdoutW, _ := os.Pipe()
|
||||
os.Stdout = stdoutW
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
|
||||
stdoutC := make(chan string)
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
_, _ = io.Copy(&buf, stdoutR)
|
||||
stdoutC <- buf.String()
|
||||
}()
|
||||
stdoutW.Close()
|
||||
|
||||
stdout := <-stdoutC
|
||||
assert.NotEmpty(t, stdout, "output should not be empty")
|
||||
assert.Contains(t, stdout, content)
|
||||
}
|
||||
Reference in New Issue
Block a user