-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support resolving Azure identities from VM scale set for SQL Server connections #51671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b19b03c
3d7d927
7a162a7
450dc13
5dcd87a
19b2dee
3f36da6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,116 @@ func TestGetVirtualMachine(t *testing.T) { | |
| }, | ||
| } { | ||
| t.Run(tc.desc, func(t *testing.T) { | ||
| vmClient := NewVirtualMachinesClientByAPI(tc.client) | ||
| vmClient := NewVirtualMachinesClientByAPI(tc.client, nil /* scaleSetAPI */) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe use the mock here. it doesn't have to mock anything but it's better nil in my opinion. Or, since it's the same api call, we could also merge the test below here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that this test case shouldn't rely on the secondary client. If that happens, the test will fail with a panic (which would indicate the client's misusage). We could use a mock that always returns an error, but that could also cause false positives when the tests expect an error. |
||
|
|
||
| vm, err := vmClient.Get(ctx, tc.resourceID) | ||
| tc.assertError(t, err) | ||
| tc.assertVM(t, vm) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGetScaleSetVirtualMachine(t *testing.T) { | ||
| ctx := context.Background() | ||
| validResourceID := "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0" | ||
|
|
||
| for _, tc := range []struct { | ||
| desc string | ||
| resourceID string | ||
| client *ARMScaleSetMock | ||
| assertError require.ErrorAssertionFunc | ||
| assertVM require.ValueAssertionFunc | ||
| }{ | ||
| { | ||
| desc: "vm with valid user identities", | ||
| resourceID: validResourceID, | ||
| client: &ARMScaleSetMock{ | ||
| GetResult: armcompute.VirtualMachineScaleSetVM{ | ||
| ID: to.Ptr(validResourceID), | ||
| Name: to.Ptr("name"), | ||
| Identity: &armcompute.VirtualMachineIdentity{ | ||
| PrincipalID: to.Ptr("system assigned"), | ||
| Type: to.Ptr(armcompute.ResourceIdentityTypeSystemAssigned), | ||
| UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{ | ||
| "identity1": {}, | ||
| "identity2": {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| assertError: require.NoError, | ||
| assertVM: func(t require.TestingT, val interface{}, _ ...interface{}) { | ||
| require.NotNil(t, val) | ||
| vm, ok := val.(*VirtualMachine) | ||
| require.Truef(t, ok, "expected *VirtualMachine, got %T", val) | ||
| require.Equal(t, vm.ID, validResourceID) | ||
| require.Equal(t, "name", vm.Name) | ||
| require.ElementsMatch(t, []Identity{ | ||
| {ResourceID: "system assigned"}, | ||
| {ResourceID: "identity1"}, | ||
| {ResourceID: "identity2"}, | ||
| }, vm.Identities) | ||
| }, | ||
| }, | ||
| { | ||
| desc: "vm without identity", | ||
| resourceID: validResourceID, | ||
| client: &ARMScaleSetMock{ | ||
| GetResult: armcompute.VirtualMachineScaleSetVM{ | ||
| ID: to.Ptr(validResourceID), | ||
| Name: to.Ptr("name"), | ||
| }, | ||
| }, | ||
| assertError: require.NoError, | ||
| assertVM: func(t require.TestingT, val interface{}, _ ...interface{}) { | ||
| require.NotNil(t, val) | ||
| vm, ok := val.(*VirtualMachine) | ||
| require.Truef(t, ok, "expected *VirtualMachine, got %T", val) | ||
| require.Equal(t, vm.ID, validResourceID) | ||
| require.Equal(t, "name", vm.Name) | ||
| require.Empty(t, vm.Identities) | ||
| }, | ||
| }, | ||
| { | ||
| desc: "vm with only user managed identities", | ||
| resourceID: validResourceID, | ||
| client: &ARMScaleSetMock{ | ||
| GetResult: armcompute.VirtualMachineScaleSetVM{ | ||
| ID: to.Ptr(validResourceID), | ||
| Name: to.Ptr("name"), | ||
| Identity: &armcompute.VirtualMachineIdentity{ | ||
| UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{ | ||
| "identity1": {}, | ||
| "identity2": {}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| assertError: require.NoError, | ||
| assertVM: func(t require.TestingT, val interface{}, _ ...interface{}) { | ||
| require.NotNil(t, val) | ||
| vm, ok := val.(*VirtualMachine) | ||
| require.Truef(t, ok, "expected *VirtualMachine, got %T", val) | ||
| require.Equal(t, vm.ID, validResourceID) | ||
| require.Equal(t, "name", vm.Name) | ||
| require.ElementsMatch(t, []Identity{ | ||
| {ResourceID: "identity1"}, | ||
| {ResourceID: "identity2"}, | ||
| }, vm.Identities) | ||
| }, | ||
| }, | ||
| { | ||
| desc: "client error", | ||
| resourceID: validResourceID, | ||
| client: &ARMScaleSetMock{ | ||
| GetErr: fmt.Errorf("client error"), | ||
| }, | ||
| assertError: require.Error, | ||
| assertVM: require.Nil, | ||
| }, | ||
| } { | ||
| t.Run(tc.desc, func(t *testing.T) { | ||
| vmClient := NewVirtualMachinesClientByAPI(nil /* api */, tc.client) | ||
|
|
||
| vm, err := vmClient.Get(ctx, tc.resourceID) | ||
| tc.assertError(t, err) | ||
|
|
@@ -184,7 +293,7 @@ func TestListVirtualMachines(t *testing.T) { | |
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| client := NewVirtualMachinesClientByAPI(mockAPI) | ||
| client := NewVirtualMachinesClientByAPI(mockAPI, nil /* scaleSetAPI */) | ||
|
|
||
| vms, err := client.ListVirtualMachines(context.Background(), tc.resourceGroup) | ||
| require.NoError(t, err) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.