From 12e462afa12685b7de702f58e74b3809c55aa7c1 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Thu, 23 Mar 2023 10:32:33 +0100 Subject: [PATCH] added parsing tests Signed-off-by: Christian Goll --- internal/app/wwctl/node/add/main_test.go | 57 +++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/internal/app/wwctl/node/add/main_test.go b/internal/app/wwctl/node/add/main_test.go index 98c8e47e..8fa8ed35 100644 --- a/internal/app/wwctl/node/add/main_test.go +++ b/internal/app/wwctl/node/add/main_test.go @@ -16,6 +16,7 @@ func Test_Add(t *testing.T) { args []string wantErr bool stdout string + chkout bool outDb string }{ {name: "single node add", @@ -39,6 +40,51 @@ nodes: n01: profiles: - foo +`}, + {name: "single node add, discoverable true, explicit", + args: []string{"--discoverable=true", "n01"}, + wantErr: false, + stdout: "", + outDb: `WW_INTERNAL: 43 +nodeprofiles: {} +nodes: + n01: + discoverable: "true" + profiles: + - default +`}, + {name: "single node add, discoverable true with yes", + args: []string{"--discoverable=yes", "n01"}, + wantErr: false, + stdout: "", + outDb: `WW_INTERNAL: 43 +nodeprofiles: {} +nodes: + n01: + discoverable: "true" + profiles: + - default +`}, + {name: "single node add, discoverable wrong argument", + args: []string{"--discoverable=maybe", "n01"}, + wantErr: true, + stdout: "", + chkout: false, + outDb: `WW_INTERNAL: 43 +nodeprofiles: {} +nodes: {} +`}, + {name: "single node add, discoverable false", + args: []string{"--discoverable=false", "n01"}, + wantErr: false, + stdout: "", + outDb: `WW_INTERNAL: 43 +nodeprofiles: {} +nodes: + n01: + discoverable: "false" + profiles: + - default `}, {name: "single node add with Kernel args", args: []string{"--kernelargs=foo", "n01"}, @@ -94,6 +140,15 @@ nodes: network devices: default: ipaddr: 10.0.0.1 +`}, + {name: "single node with malformed ipaddr", + args: []string{"--ipaddr=10.0.1", "n01"}, + wantErr: true, + stdout: "", + chkout: false, + outDb: `WW_INTERNAL: 43 +nodeprofiles: {} +nodes: {} `}, {name: "three nodes with ipaddr", args: []string{"--ipaddr=10.10.0.1", "n[01-02,03]"}, @@ -212,7 +267,7 @@ WW_INTERNAL: 43 t.Errorf("DB dump is wrong, got:'%s'\nwant:'%s'", dump, tt.outDb) t.FailNow() } - if buf.String() != tt.stdout { + if tt.chkout && buf.String() != tt.stdout { t.Errorf("Got wrong output, got:'%s'\nwant:'%s'", buf.String(), tt.stdout) t.FailNow() }