@@ -440,6 +440,85 @@ func TestNodeTemplateResourceCreate_defaultNodeTemplate(t *testing.T) {
440440 r .False (result .HasError ())
441441}
442442
443+ func TestNodeTemplateResourceCreate_customNodeTemplate (t * testing.T ) {
444+ r := require .New (t )
445+ mockctrl := gomock .NewController (t )
446+ mockClient := mock_sdk .NewMockClientInterface (mockctrl )
447+
448+ ctx := context .Background ()
449+ provider := & ProviderConfig {
450+ api : & sdk.ClientWithResponses {
451+ ClientInterface : mockClient ,
452+ },
453+ }
454+
455+ name := "custom-template"
456+ clusterId := "b6bfc074-a267-400f-b8f1-db0850c369b1"
457+ templateResponse := `
458+ {
459+ "configurationId": "7dc4f922-29c9-4377-889c-0c8c5fb8d497",
460+ "configurationName": "default",
461+ "name": "custom-template",
462+ "isEnabled": false,
463+ "constraints": {
464+ "spot": false,
465+ "onDemand": true,
466+ "minCpu": 10,
467+ "maxCpu": 10000,
468+ "architectures": ["amd64", "arm64"],
469+ "resourceLimits": {
470+ "cpuLimitEnabled": true,
471+ "cpuLimitMaxCores": 20
472+ }
473+ },
474+ "version": "3",
475+ "shouldTaint": true,
476+ "customLabels": {},
477+ "customTaints": [],
478+ "rebalancingConfig": {
479+ "minNodes": 0
480+ },
481+ "customInstancesEnabled": true,
482+ "customInstancesWithExtendedMemoryEnabled": true
483+ }
484+ `
485+
486+ templateBody := io .NopCloser (bytes .NewReader ([]byte (templateResponse )))
487+ listBody := io .NopCloser (bytes .NewReader ([]byte (fmt .Sprintf (`
488+ {
489+ "items": [
490+ {
491+ "template": %s
492+ }
493+ ]
494+ }
495+ ` , templateResponse ))))
496+
497+ mockClient .EXPECT ().
498+ NodeTemplatesAPIListNodeTemplates (gomock .Any (), clusterId , & sdk.NodeTemplatesAPIListNodeTemplatesParams {IncludeDefault : lo .ToPtr (true )}).
499+ Return (& http.Response {StatusCode : 200 , Body : listBody , Header : map [string ][]string {"Content-Type" : {"json" }}}, nil )
500+ mockClient .EXPECT ().
501+ NodeTemplatesAPICreateNodeTemplate (gomock .Any (), clusterId , gomock .Any ()).
502+ Return (& http.Response {StatusCode : 200 , Body : templateBody , Header : map [string ][]string {"Content-Type" : {"json" }}}, nil )
503+
504+ resource := resourceNodeTemplate ()
505+ val := cty .ObjectVal (map [string ]cty.Value {
506+ FieldClusterId : cty .StringVal (clusterId ),
507+ FieldNodeTemplateName : cty .StringVal (name ),
508+ FieldNodeTemplateIsDefault : cty .BoolVal (true ),
509+ FieldNodeTemplateIsEnabled : cty .BoolVal (false ),
510+ FieldNodeTemplateCustomInstancesEnabled : cty .BoolVal (true ),
511+ FieldNodeTemplateCustomInstancesWithExtendedMemoryEnabled : cty .BoolVal (true ),
512+ })
513+ state := terraform .NewInstanceStateShimmedFromValue (val , 0 )
514+ state .ID = name
515+
516+ data := resource .Data (state )
517+ result := resource .CreateContext (ctx , data , provider )
518+ r .Nil (result )
519+ r .False (result .HasError ())
520+ }
521+
443522func TestNodeTemplateResourceDelete_defaultNodeTemplate (t * testing.T ) {
444523 r := require .New (t )
445524 mockctrl := gomock .NewController (t )
0 commit comments