Skip to content

Commit ccaac59

Browse files
committed
use proper constructor and improve tests
1 parent 24fbb6f commit ccaac59

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

internal/validation/suite.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ func RunInstanceLifecycleValidation(t *testing.T, config ProviderConfig) {
7979

8080
t.Run("ValidateCreateInstance", func(t *testing.T) {
8181
attrs := v1.CreateInstanceAttrs{}
82+
selectedType := v1.InstanceType{}
8283
for _, typ := range types {
8384
if typ.IsAvailable {
8485
attrs.InstanceType = typ.Type
8586
attrs.Location = typ.Location
8687
attrs.PublicKey = ssh.GetTestPublicKey()
88+
selectedType = typ
8789
break
8890
}
8991
}
90-
instance, err := v1.ValidateCreateInstance(ctx, client, attrs)
92+
instance, err := v1.ValidateCreateInstance(ctx, client, attrs, selectedType)
9193
if err != nil {
9294
t.Fatalf("ValidateCreateInstance failed: %v", err)
9395
}

v1/instance.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type CloudCreateTerminateInstance interface {
2828
CloudInstanceReader
2929
}
3030

31-
func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInstance, attrs CreateInstanceAttrs) (*Instance, error) {
31+
func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInstance, attrs CreateInstanceAttrs, selectedType InstanceType) (*Instance, error) {
3232
t0 := time.Now().Add(-time.Minute)
3333
attrs.RefID = uuid.New().String()
3434
name, err := makeDebuggableName(attrs.Name)
@@ -67,6 +67,9 @@ func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInst
6767
if attrs.InstanceType != "" && attrs.InstanceType != i.InstanceType {
6868
validationErr = errors.Join(validationErr, fmt.Errorf("instanceType mismatch: %s != %s", attrs.InstanceType, i.InstanceType))
6969
}
70+
if selectedType.ID != "" && selectedType.ID != i.InstanceTypeID {
71+
validationErr = errors.Join(validationErr, fmt.Errorf("instanceTypeID mismatch: %s != %s", selectedType.ID, i.InstanceTypeID))
72+
}
7073

7174
return i, validationErr
7275
}

v1/providers/nebius/instance.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,14 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance *
334334
sshUser = "admin"
335335
}
336336

337-
return &v1.Instance{
337+
inst := &v1.Instance{
338338
RefID: refID,
339339
CloudCredRefID: c.refID,
340340
Name: instance.Metadata.Name,
341341
CloudID: instanceID,
342342
Location: location,
343343
CreatedAt: createdAt,
344344
InstanceType: instanceTypeID, // Full instance type ID (e.g., "gpu-h100-sxm.8gpu-128vcpu-1600gb")
345-
InstanceTypeID: v1.InstanceTypeID(getInstanceTypeID(instanceTypeID, location)),
346345
ImageID: imageFamily,
347346
DiskSize: units.Base2Bytes(diskSize),
348347
DiskSizeBytes: v1.NewBytes(v1.BytesValue(diskSize), v1.Byte), // diskSize is already in bytes from getBootDiskSize
@@ -355,11 +354,9 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance *
355354
Hostname: hostname,
356355
SSHUser: sshUser,
357356
SSHPort: 22, // Standard SSH port
358-
}, nil
359-
}
360-
361-
func getInstanceTypeID(instanceType string, region string) string {
362-
return fmt.Sprintf("%v-%v", instanceType, region)
357+
}
358+
inst.InstanceTypeID = v1.MakeGenericInstanceTypeIDFromInstance(*inst)
359+
return inst, nil
363360
}
364361

365362
// waitForInstanceRunning polls the instance until it reaches RUNNING state or fails

0 commit comments

Comments
 (0)