fix test to run without NodeInfo
Also removed --fullall from node list and profile list Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
ffef31969e
commit
ac6cd69ca6
@@ -2,14 +2,11 @@ package list
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
@@ -17,44 +14,50 @@ import (
|
||||
|
||||
func Test_List_Args(t *testing.T) {
|
||||
tests := []struct {
|
||||
args []string
|
||||
output string
|
||||
fail bool
|
||||
name string
|
||||
args []string
|
||||
stdout string
|
||||
inDb string
|
||||
mockFunc func()
|
||||
}{
|
||||
{args: []string{""},
|
||||
output: ` CONTAINER NAME
|
||||
test
|
||||
{
|
||||
name: "container list test",
|
||||
args: []string{"-l"},
|
||||
stdout: ` CONTAINER NAME NODES KERNEL VERSION CREATION TIME MODIFICATION TIME SIZE
|
||||
test 1 kernel`,
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
fail: false,
|
||||
},
|
||||
{args: []string{"-l"},
|
||||
output: ` CONTAINER NAME NODES KERNEL VERSION CREATION TIME MODIFICATION TIME SIZE
|
||||
test 0 02 Jan 00 03:04 UTC 01 Jan 70 00:00 UTC 0 B
|
||||
`,
|
||||
fail: false,
|
||||
},
|
||||
{args: []string{"-c"},
|
||||
output: ` CONTAINER NAME NODES SIZE
|
||||
test 0 37 B
|
||||
`,
|
||||
fail: false,
|
||||
mockFunc: func() {
|
||||
containerList = func() (containerInfo []*wwapiv1.ContainerInfo, err error) {
|
||||
containerInfo = append(containerInfo, &wwapiv1.ContainerInfo{
|
||||
Name: "test",
|
||||
NodeCount: 1,
|
||||
KernelVersion: "kernel",
|
||||
CreateDate: uint64(time.Unix(0, 0).Unix()),
|
||||
ModDate: uint64(time.Unix(0, 0).Unix()),
|
||||
Size: uint64(1),
|
||||
})
|
||||
return
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, path.Join(testenv.WWChrootdir, "test/rootfs/bin/sh"), `This is a fake shell, no pearls here.`)
|
||||
// need to touch the files, so that the creation date of the container is constant,
|
||||
// modification date of `../chroots/containername` is used as creation date.
|
||||
// modification dates of directories change every time a file or subdir is added
|
||||
// so we have to make it constant *after* its creation.
|
||||
cmd := exec.Command("touch", "-d", "2000-01-02 03:04:05 UTC",
|
||||
env.GetPath(path.Join(testenv.WWChrootdir, "test/rootfs")),
|
||||
env.GetPath(path.Join(testenv.WWChrootdir, "test")))
|
||||
err := cmd.Run()
|
||||
assert.NoError(t, err)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
warewulfd.SetNoDaemon()
|
||||
for _, tt := range tests {
|
||||
t.Run(strings.Join(tt.args, "_"), func(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||
|
||||
t.Logf("Running test: %s\n", tt.name)
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.mockFunc()
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
stdoutR, stdoutW, _ := os.Pipe()
|
||||
|
||||
Reference in New Issue
Block a user