Add test that verifies disksize bug (1/2)
This commit is contained in:
parent
eb5dc9326d
commit
98175c06d5
@ -19,7 +19,7 @@ const (
|
|||||||
// Tests assume current machine is capable of running chroot builder (i.e. an Azure VM)
|
// Tests assume current machine is capable of running chroot builder (i.e. an Azure VM)
|
||||||
|
|
||||||
func Test_DiskAttacherAttachesDiskToVM(t *testing.T) {
|
func Test_DiskAttacherAttachesDiskToVM(t *testing.T) {
|
||||||
azcli, err := client.GetTestClientSet(t)
|
azcli, err := client.GetTestClientSet(t) // integration test
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
da := NewDiskAttacher(azcli)
|
da := NewDiskAttacher(azcli)
|
||||||
testDiskName := t.Name()
|
testDiskName := t.Name()
|
||||||
|
@ -49,7 +49,6 @@ func (s StepCreateNewDisk) Run(ctx context.Context, state multistep.StateBag) mu
|
|||||||
OsType: "Linux",
|
OsType: "Linux",
|
||||||
HyperVGeneration: compute.HyperVGeneration(s.HyperVGeneration),
|
HyperVGeneration: compute.HyperVGeneration(s.HyperVGeneration),
|
||||||
CreationData: &compute.CreationData{},
|
CreationData: &compute.CreationData{},
|
||||||
DiskSizeGB: to.Int32Ptr(s.DiskSizeGB),
|
|
||||||
},
|
},
|
||||||
//Tags: map[string]*string{
|
//Tags: map[string]*string{
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -14,8 +15,28 @@ import (
|
|||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_StepCreateNewDisk_FromDisk(t *testing.T) {
|
func TestStepCreateNewDisk_Run(t *testing.T) {
|
||||||
sut := StepCreateNewDisk{
|
type fields struct {
|
||||||
|
SubscriptionID string
|
||||||
|
ResourceGroup string
|
||||||
|
DiskName string
|
||||||
|
DiskSizeGB int32
|
||||||
|
DiskStorageAccountType string
|
||||||
|
HyperVGeneration string
|
||||||
|
Location string
|
||||||
|
PlatformImage *client.PlatformImage
|
||||||
|
SourceDiskResourceID string
|
||||||
|
|
||||||
|
expectedPutDiskBody string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
want multistep.StepAction
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "HappyPathDiskSource",
|
||||||
|
fields: fields{
|
||||||
SubscriptionID: "SubscriptionID",
|
SubscriptionID: "SubscriptionID",
|
||||||
ResourceGroup: "ResourceGroupName",
|
ResourceGroup: "ResourceGroupName",
|
||||||
DiskName: "TemporaryOSDiskName",
|
DiskName: "TemporaryOSDiskName",
|
||||||
@ -24,10 +45,9 @@ func Test_StepCreateNewDisk_FromDisk(t *testing.T) {
|
|||||||
HyperVGeneration: string(compute.V1),
|
HyperVGeneration: string(compute.V1),
|
||||||
Location: "westus",
|
Location: "westus",
|
||||||
SourceDiskResourceID: "SourceDisk",
|
SourceDiskResourceID: "SourceDisk",
|
||||||
}
|
|
||||||
|
|
||||||
expected := regexp.MustCompile(`[\s\n]`).ReplaceAllString(`
|
expectedPutDiskBody: `
|
||||||
{
|
{
|
||||||
"location": "westus",
|
"location": "westus",
|
||||||
"properties": {
|
"properties": {
|
||||||
"osType": "Linux",
|
"osType": "Linux",
|
||||||
@ -41,13 +61,71 @@ func Test_StepCreateNewDisk_FromDisk(t *testing.T) {
|
|||||||
"sku": {
|
"sku": {
|
||||||
"name": "Premium_LRS"
|
"name": "Premium_LRS"
|
||||||
}
|
}
|
||||||
}`, "")
|
}`,
|
||||||
|
},
|
||||||
|
want: multistep.ActionContinue,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "HappyPathDiskSource",
|
||||||
|
fields: fields{
|
||||||
|
SubscriptionID: "SubscriptionID",
|
||||||
|
ResourceGroup: "ResourceGroupName",
|
||||||
|
DiskName: "TemporaryOSDiskName",
|
||||||
|
DiskStorageAccountType: string(compute.StandardLRS),
|
||||||
|
HyperVGeneration: string(compute.V1),
|
||||||
|
Location: "westus",
|
||||||
|
PlatformImage: &client.PlatformImage{
|
||||||
|
Publisher: "Microsoft",
|
||||||
|
Offer: "Windows",
|
||||||
|
Sku: "2016-DataCenter",
|
||||||
|
Version: "2016.1.4",
|
||||||
|
},
|
||||||
|
|
||||||
|
expectedPutDiskBody: `
|
||||||
|
{
|
||||||
|
"location": "westus",
|
||||||
|
"properties": {
|
||||||
|
"osType": "Linux",
|
||||||
|
"hyperVGeneration": "V1",
|
||||||
|
"creationData": {
|
||||||
|
"createOption":"FromImage",
|
||||||
|
"imageReference": {
|
||||||
|
"id":"/subscriptions/SubscriptionID/providers/Microsoft.Compute/locations/westus/publishers/Microsoft/artifacttypes/vmimage/offers/Windows/skus/2016-DataCenter/versions/2016.1.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sku": {
|
||||||
|
"name": "Standard_LRS"
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
want: multistep.ActionContinue,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
s := StepCreateNewDisk{
|
||||||
|
SubscriptionID: tt.fields.SubscriptionID,
|
||||||
|
ResourceGroup: tt.fields.ResourceGroup,
|
||||||
|
DiskName: tt.fields.DiskName,
|
||||||
|
DiskSizeGB: tt.fields.DiskSizeGB,
|
||||||
|
DiskStorageAccountType: tt.fields.DiskStorageAccountType,
|
||||||
|
HyperVGeneration: tt.fields.HyperVGeneration,
|
||||||
|
Location: tt.fields.Location,
|
||||||
|
PlatformImage: tt.fields.PlatformImage,
|
||||||
|
SourceDiskResourceID: tt.fields.SourceDiskResourceID,
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedPutDiskBody := regexp.MustCompile(`[\s\n]`).ReplaceAllString(tt.fields.expectedPutDiskBody, "")
|
||||||
|
|
||||||
m := compute.NewDisksClient("subscriptionId")
|
m := compute.NewDisksClient("subscriptionId")
|
||||||
m.Sender = autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
|
m.Sender = autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
|
||||||
|
if r.Method != "PUT" {
|
||||||
|
t.Fatal("Expected only a PUT disk call")
|
||||||
|
}
|
||||||
b, _ := ioutil.ReadAll(r.Body)
|
b, _ := ioutil.ReadAll(r.Body)
|
||||||
if string(b) != expected {
|
if string(b) != expectedPutDiskBody {
|
||||||
t.Fatalf("expected body to be %q, but got %q", expected, string(b))
|
t.Fatalf("expected body to be %q, but got %q", expectedPutDiskBody, string(b))
|
||||||
}
|
}
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
Request: r,
|
Request: r,
|
||||||
@ -61,9 +139,9 @@ func Test_StepCreateNewDisk_FromDisk(t *testing.T) {
|
|||||||
})
|
})
|
||||||
state.Put("ui", packer.TestUi(t))
|
state.Put("ui", packer.TestUi(t))
|
||||||
|
|
||||||
r := sut.Run(context.TODO(), state)
|
if got := s.Run(context.TODO(), state); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("StepCreateNewDisk.Run() = %v, want %v", got, tt.want)
|
||||||
if r != multistep.ActionContinue {
|
}
|
||||||
t.Fatal("Run failed")
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user