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
117
internal/app/wwctl/profile/set/main_test.go
Normal file
117
internal/app/wwctl/profile/set/main_test.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package set
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
type test_description struct {
|
||||
name string
|
||||
args []string
|
||||
wantErr bool
|
||||
stdout string
|
||||
inDB string
|
||||
outDb string
|
||||
}
|
||||
|
||||
func run_test(t *testing.T, test test_description) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", test.inDB)
|
||||
warewulfd.SetNoDaemon()
|
||||
name := test.name
|
||||
if name == "" {
|
||||
name = t.Name()
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
test.args = append(test.args, "--yes")
|
||||
baseCmd.SetArgs(test.args)
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
err := baseCmd.Execute()
|
||||
if test.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, buf.String(), test.stdout)
|
||||
content := env.ReadFile(t, "etc/warewulf/nodes.conf")
|
||||
assert.YAMLEq(t, test.outDb, content)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Set_Netdev(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--netname=default", "--netdev=eth0", "default"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes: {}
|
||||
`,
|
||||
outDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
nodes: {}
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
func Test_Set_Netdev_and_Mask(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--netname=default", "--netdev=eth0", "-M=255.255.255.0", "default"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes: {}
|
||||
`,
|
||||
outDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
netmask: 255.255.255.0
|
||||
nodes: {}
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
|
||||
func Test_Set_Mask_Existing_NetDev(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--netname=default", "-M=255.255.255.0", "default"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
nodes: {}
|
||||
`,
|
||||
outDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
netmask: 255.255.255.0
|
||||
nodes: {}
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
Reference in New Issue
Block a user