From 749857b07cbcc8d00b0011f52204155bfeb273c9 Mon Sep 17 00:00:00 2001 From: weihuanhuan Date: Sat, 14 Sep 2024 17:55:49 +0800 Subject: [PATCH] update infra func --- cmd/deploy_test.go | 33 +++++++++++++++ .../asset/infraasset/infraasset_test.go | 42 ++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/cmd/deploy_test.go b/cmd/deploy_test.go index cc9b916..094a4cd 100644 --- a/cmd/deploy_test.go +++ b/cmd/deploy_test.go @@ -22,6 +22,7 @@ import ( "nestos-kubernetes-deployer/pkg/configmanager/asset/infraasset" "nestos-kubernetes-deployer/pkg/configmanager/globalconfig" "nestos-kubernetes-deployer/pkg/httpserver" + "nestos-kubernetes-deployer/pkg/utils" "net/http" "net/http/httptest" "os" @@ -78,6 +79,10 @@ func TestDeploy(t *testing.T) { RAM: 2048, Disk: 30, }, + Certs: []utils.StorageContent{{ + Path: "sss", + Mode: 44, + }}, }, }, Worker: []asset.NodeAsset{ @@ -191,6 +196,9 @@ func TestDeploy(t *testing.T) { "cluster": cc, } cc.Platform = "libvirt" + cc.InfraPlatform = &infraasset.LibvirtAsset{ + URI: "sss", + } cc.OSImage = asset.OSImage{Type: "generalos"} err := createCluster(cc) if err != nil { @@ -200,6 +208,27 @@ func TestDeploy(t *testing.T) { t.Run("createCluster libvirt", func(t *testing.T) { cc.Platform = "libvirt" + cc.InfraPlatform = &infraasset.LibvirtAsset{ + URI: "sss", + } + cc.OSImage = asset.OSImage{Type: "generalos"} + configmanager.GlobalConfig = &globalconfig.GlobalConfig{} + configmanager.ClusterAsset = map[string]*asset.ClusterAsset{ + "cluster": cc, + } + + err := createCluster(cc) + if err != nil { + t.Log("createCluster Expected error, got nil") + } + }) + + t.Run("createCluster libvirt", func(t *testing.T) { + cc.Platform = "ipxe" + cc.InfraPlatform = &infraasset.IPXEAsset{ + IP: "8888", + Port: "00", + } cc.OSImage = asset.OSImage{Type: "generalos"} configmanager.GlobalConfig = &globalconfig.GlobalConfig{} configmanager.ClusterAsset = map[string]*asset.ClusterAsset{ @@ -211,6 +240,10 @@ func TestDeploy(t *testing.T) { t.Log("createCluster Expected error, got nil") } }) + t.Run("getClusterConfig", func(t *testing.T) { + getClusterConfig(&opts.Opts) + }) + t.Run("getClusterConfig", func(t *testing.T) { getClusterConfig(&opts.Opts) }) diff --git a/pkg/configmanager/asset/infraasset/infraasset_test.go b/pkg/configmanager/asset/infraasset/infraasset_test.go index 978918c..83d12df 100644 --- a/pkg/configmanager/asset/infraasset/infraasset_test.go +++ b/pkg/configmanager/asset/infraasset/infraasset_test.go @@ -126,10 +126,50 @@ func TestInfra(t *testing.T) { }) t.Run("InitInfraAsset Fail", func(t *testing.T) { - cc.Platform = "test" + cc.Platform = "ipxe" _, err := InitInfraAsset(cc, opts) if err == nil { t.Log("Expected error, got nil") } }) + + t.Run("InitInfraAsset Fail", func(t *testing.T) { + cc.Platform = "sssssss" + _, err := InitInfraAsset(cc, opts) + if err == nil { + t.Log("Expected error, got nil") + } + }) + t.Run("convertMap Fail", func(t *testing.T) { + arr := []string{"libvirt", "openstack", "pxe", "ipxe"} + for _, k := range arr { + _, b := convertMap(nil, k) + if !b { + t.Log("Expected error, got nil") + } + } + + }) + + t.Run("convertMap Fail", func(t *testing.T) { + arr := []string{"libvirt", "openstack", "pxe", "ipxe"} + for _, k := range arr { + cc.Platform = k + cc.InfraPlatform = nil + _, err := InitInfraAsset(cc, opts) + if err != nil { + t.Logf("Expected error, got:%v", err.Error()) + } + } + + }) + t.Run("convertMap Fail3333", func(t *testing.T) { + v := map[string]string{} + v["sss"] = "sss" + _, b := convertMap(v, "sss") + if !b { + t.Log("Expected error, got nil") + } + + }) } -- Gitee