@@ -15,6 +15,7 @@ import (
1515 "time"
1616
1717 "github.com/scott-the-programmer/terraform-provider-minikube/minikube/lib"
18+ "github.com/scott-the-programmer/terraform-provider-minikube/minikube/state_utils"
1819
1920 "github.com/golang/mock/gomock"
2021 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -35,12 +36,14 @@ type mockClusterClientProperties struct {
3536 haNodes int
3637 workerNodes int
3738 diskSize int
39+ memory string
40+ cpu string
3841}
3942
4043func TestClusterCreation (t * testing.T ) {
4144 resource .Test (t , resource.TestCase {
4245 IsUnitTest : true ,
43- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreation" , 1 , 0 , 20000 }))},
46+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreation" , 1 , 0 , 20000 , "4096mb" , "1" }))},
4447 Steps : []resource.TestStep {
4548 {
4649 Config : testUnitClusterConfig ("some_driver" , "TestClusterCreation" ),
@@ -55,7 +58,7 @@ func TestClusterCreation(t *testing.T) {
5558func TestClusterUpdate (t * testing.T ) {
5659 resource .Test (t , resource.TestCase {
5760 IsUnitTest : true ,
58- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockUpdate (mockClusterClientProperties {t , "TestClusterUpdate" , 1 , 0 , 20000 }))},
61+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockUpdate (mockClusterClientProperties {t , "TestClusterUpdate" , 1 , 0 , 20000 , "4096mb" , "1" }))},
5962 Steps : []resource.TestStep {
6063 {
6164 Config : testUnitClusterConfig ("some_driver" , "TestClusterUpdate" ),
@@ -73,7 +76,7 @@ func TestClusterUpdate(t *testing.T) {
7376func TestClusterHA (t * testing.T ) {
7477 resource .Test (t , resource.TestCase {
7578 IsUnitTest : true ,
76- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreationHA" , 3 , 5 , 20000 }))},
79+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreationHA" , 3 , 5 , 20000 , "4096mb" , "1" }))},
7780 Steps : []resource.TestStep {
7881 {
7982 Config : testUnitClusterHAConfig ("some_driver" , "TestClusterCreationHA" ),
@@ -85,7 +88,7 @@ func TestClusterHA(t *testing.T) {
8588func TestClusterDisk (t * testing.T ) {
8689 resource .Test (t , resource.TestCase {
8790 IsUnitTest : true ,
88- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreationDisk" , 1 , 0 , 20480 }))},
91+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreationDisk" , 1 , 0 , 20480 , "4096mb" , "1" }))},
8992 Steps : []resource.TestStep {
9093 {
9194 Config : testUnitClusterDiskConfig ("some_driver" , "TestClusterCreationDisk" ),
@@ -97,7 +100,7 @@ func TestClusterDisk(t *testing.T) {
97100func TestClusterWait (t * testing.T ) {
98101 resource .Test (t , resource.TestCase {
99102 IsUnitTest : true ,
100- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreationWait" , 1 , 0 , 20000 }))},
103+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterCreationWait" , 1 , 0 , 20000 , "4096mb" , "1" }))},
101104 Steps : []resource.TestStep {
102105 {
103106 Config : testUnitClusterWaitConfig ("some_driver" , "TestClusterCreationWait" ),
@@ -329,7 +332,7 @@ func TestClusterCreation_HyperV(t *testing.T) {
329332func TestClusterNoLimitMemory (t * testing.T ) {
330333 resource .Test (t , resource.TestCase {
331334 IsUnitTest : true ,
332- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterNoLimitMemory" , 1 , 0 , 20000 }))},
335+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterNoLimitMemory" , 1 , 0 , 20000 , "no-limit" , "1" }))},
333336 Steps : []resource.TestStep {
334337 {
335338 Config : testUnitClusterNoLimitMemoryConfig ("some_driver" , "TestClusterNoLimitMemory" ),
@@ -341,7 +344,7 @@ func TestClusterNoLimitMemory(t *testing.T) {
341344func TestClusterMaxMemory (t * testing.T ) {
342345 resource .Test (t , resource.TestCase {
343346 IsUnitTest : true ,
344- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterMaxMemory" , 1 , 0 , 20000 }))},
347+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterMaxMemory" , 1 , 0 , 20000 , "max" , "1" }))},
345348 Steps : []resource.TestStep {
346349 {
347350 Config : testUnitClusterMaxMemoryConfig ("some_driver" , "TestClusterMaxMemory" ),
@@ -353,7 +356,7 @@ func TestClusterMaxMemory(t *testing.T) {
353356func TestClusterNoLimitCPU (t * testing.T ) {
354357 resource .Test (t , resource.TestCase {
355358 IsUnitTest : true ,
356- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterNoLimitCPU" , 1 , 0 , 20000 }))},
359+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterNoLimitCPU" , 1 , 0 , 20000 , "4096mb" , "no-limit" }))},
357360 Steps : []resource.TestStep {
358361 {
359362 Config : testUnitClusterNoLimitCPUConfig ("some_driver" , "TestClusterNoLimitCPU" ),
@@ -365,7 +368,7 @@ func TestClusterNoLimitCPU(t *testing.T) {
365368func TestClusterMaxCPU (t * testing.T ) {
366369 resource .Test (t , resource.TestCase {
367370 IsUnitTest : true ,
368- Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterMaxCPU" , 1 , 0 , 20000 }))},
371+ Providers : map [string ]* schema.Provider {"minikube" : NewProvider (mockSuccess (mockClusterClientProperties {t , "TestClusterMaxCPU" , 1 , 0 , 20000 , "4096mb" , "max" }))},
369372 Steps : []resource.TestStep {
370373 {
371374 Config : testUnitClusterMaxCPUConfig ("some_driver" , "TestClusterMaxCPU" ),
@@ -377,7 +380,7 @@ func TestClusterMaxCPU(t *testing.T) {
377380func mockUpdate (props mockClusterClientProperties ) schema.ConfigureContextFunc {
378381 ctrl := gomock .NewController (props .t )
379382
380- mockClusterClient := getBaseMockClient (ctrl , props .name , props .haNodes , props .workerNodes , props .diskSize )
383+ mockClusterClient := getBaseMockClient (props . t , ctrl , props .name , props .haNodes , props .workerNodes , props .diskSize , props . memory , props . cpu )
381384
382385 gomock .InOrder (
383386 mockClusterClient .EXPECT ().
@@ -414,7 +417,7 @@ func mockUpdate(props mockClusterClientProperties) schema.ConfigureContextFunc {
414417func mockSuccess (props mockClusterClientProperties ) schema.ConfigureContextFunc {
415418 ctrl := gomock .NewController (props .t )
416419
417- mockClusterClient := getBaseMockClient (ctrl , props .name , props .haNodes , props .workerNodes , props .diskSize )
420+ mockClusterClient := getBaseMockClient (props . t , ctrl , props .name , props .haNodes , props .workerNodes , props .diskSize , props . memory , props . cpu )
418421
419422 mockClusterClient .EXPECT ().
420423 GetAddons ().
@@ -432,7 +435,7 @@ func mockSuccess(props mockClusterClientProperties) schema.ConfigureContextFunc
432435 return configureContext
433436}
434437
435- func getBaseMockClient (ctrl * gomock.Controller , clusterName string , haNodes int , workerNodes int , diskSize int ) * lib.MockClusterClient {
438+ func getBaseMockClient (t * testing. T , ctrl * gomock.Controller , clusterName string , haNodes int , workerNodes int , diskSize int , memory string , cpu string ) * lib.MockClusterClient {
436439 mockClusterClient := lib .NewMockClusterClient (ctrl )
437440
438441 os .Mkdir ("test_output" , 0755 )
@@ -472,6 +475,16 @@ func getBaseMockClient(ctrl *gomock.Controller, clusterName string, haNodes int,
472475 Worker : true ,
473476 }
474477
478+ mem , err := state_utils .GetMemory (memory )
479+ if err != nil {
480+ t .Fatalf ("Failed to get memory: %v" , err )
481+ }
482+
483+ c , err := state_utils .GetCPUs (cpu )
484+ if err != nil {
485+ t .Fatalf ("Failed to get cpu: %v" , err )
486+ }
487+
475488 cc := config.ClusterConfig {
476489 Name : "terraform-provider-minikube-acc" ,
477490 APIServerPort : clusterSchema ["apiserver_port" ].Default .(int ),
@@ -480,8 +493,8 @@ func getBaseMockClient(ctrl *gomock.Controller, clusterName string, haNodes int,
480493 MinikubeISO : defaultIso ,
481494 KicBaseImage : clusterSchema ["base_image" ].Default .(string ),
482495 Network : clusterSchema ["network" ].Default .(string ),
483- Memory : 4096 ,
484- CPUs : 2 ,
496+ Memory : mem ,
497+ CPUs : c ,
485498 DiskSize : diskSize ,
486499 Driver : "some_driver" ,
487500 ListenAddress : clusterSchema ["listen_address" ].Default .(string ),
0 commit comments