Skip to content

Commit 0545c0c

Browse files
committed
add
1 parent 83e2093 commit 0545c0c

13 files changed

+571
-0
lines changed

generated/network_services/test/api_ike_crypto_profile_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,58 @@ func Test_networkservices_IKECryptoProfilesAPIService_List(t *testing.T) {
237237
t.Logf("Successfully listed IKE Crypto Profiles, found created profile: %s", profileName)
238238
}
239239

240+
// Test_networkservices_IKECryptoProfilesAPIService_Fetch tests the fetch convenience method.
241+
func Test_networkservices_IKECryptoProfilesAPIService_Fetch(t *testing.T) {
242+
client := SetupNetworkSvcTestClient(t)
243+
244+
// Create a profile to fetch by name.
245+
profileName := "test-ike-fetch-" + common.GenerateRandomString(6)
246+
profile := network_services.IkeCryptoProfiles{
247+
Folder: common.StringPtr("Shared"),
248+
Name: profileName,
249+
Hash: []string{"sha256"},
250+
DhGroup: []string{"group14"},
251+
Encryption: []string{"aes-256-cbc"},
252+
Lifetime: &network_services.IkeCryptoProfilesLifetime{
253+
Hours: common.Int32Ptr(8),
254+
},
255+
}
256+
257+
reqCreate := client.IKECryptoProfilesAPI.CreateIKECryptoProfiles(context.Background()).IkeCryptoProfiles(profile)
258+
createRes, _, err := reqCreate.Execute()
259+
require.NoError(t, err, "Failed to create profile for fetch test")
260+
createdProfileID := *createRes.Id
261+
createdFolder := createRes.Folder
262+
require.NotEmpty(t, createdProfileID, "Created profile ID should not be empty")
263+
264+
// Defer cleanup.
265+
defer func() {
266+
t.Logf("Cleaning up IKE Crypto Profile with ID: %s", createdProfileID)
267+
_, errDel := client.IKECryptoProfilesAPI.DeleteIKECryptoProfilesByID(context.Background(), createdProfileID).Execute()
268+
require.NoError(t, errDel, "Failed to delete profile during cleanup")
269+
}()
270+
271+
// Test Fetch by name operation.
272+
fmt.Printf("Attempting to fetch IKE Crypto Profile with name: %s\n", profileName)
273+
fetchedProfile, errFetch := client.IKECryptoProfilesAPI.FetchIKECryptoProfiles(context.Background(), profileName, createdFolder, nil, nil)
274+
275+
// Verify the fetch operation was successful.
276+
require.NoError(t, errFetch, "Failed to fetch profile by name")
277+
require.NotNil(t, fetchedProfile, "Fetched profile should not be nil")
278+
assert.Equal(t, profileName, fetchedProfile.Name, "Profile name should match")
279+
assert.Equal(t, createdProfileID, *fetchedProfile.Id, "Profile ID should match")
280+
assert.Equal(t, []string{"sha256"}, fetchedProfile.Hash, "Hash should match")
281+
assert.Equal(t, *createdFolder, *fetchedProfile.Folder, "Folder should match")
282+
t.Logf("Successfully fetched IKE Crypto Profile: %s", profileName)
283+
284+
// Test fetching non-existent profile (should return nil).
285+
nonExistentName := "non-existent-ike-profile-xyz-12345"
286+
notFoundProfile, errNotFound := client.IKECryptoProfilesAPI.FetchIKECryptoProfiles(context.Background(), nonExistentName, createdFolder, nil, nil)
287+
require.NoError(t, errNotFound, "Fetch for non-existent profile should not error")
288+
assert.Nil(t, notFoundProfile, "Non-existent profile should return nil")
289+
t.Logf("Successfully verified fetch returns nil for non-existent profile")
290+
}
291+
240292
// Test_networkservices_IKECryptoProfilesAPIService_DeleteByID tests deleting a profile by ID.
241293
func Test_networkservices_IKECryptoProfilesAPIService_DeleteByID(t *testing.T) {
242294
client := SetupNetworkSvcTestClient(t)

generated/network_services/test/api_ike_gateway_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,52 @@ func Test_networkservices_IkeGatewaysAPIService_List(t *testing.T) {
195195
t.Logf("Successfully listed IKE Gateways and found created gateway: %s", gatewayName)
196196
}
197197

198+
// Test_networkservices_IkeGatewaysAPIService_Fetch tests the fetch convenience method.
199+
func Test_networkservices_IkeGatewaysAPIService_Fetch(t *testing.T) {
200+
client := SetupNetworkSvcTestClient(t)
201+
202+
// Create the IKE Crypto Profile dependency first.
203+
randomSuffix := common.GenerateRandomString(6)
204+
cryptoProfileName := "test-crypto-fetch-" + randomSuffix
205+
cryptoProfileID := CreateTestIKECryptoProfile(t, client, cryptoProfileName)
206+
defer DeleteTestIKECryptoProfile(t, client, cryptoProfileID, cryptoProfileName)
207+
208+
// Create a gateway to fetch by name.
209+
gatewayName := "auto_ike_gw_fetch-" + randomSuffix
210+
gateway := CreateIkeGatewayTestObject(gatewayName, cryptoProfileName)
211+
createRes, _, err := client.IKEGatewaysAPI.CreateIKEGateways(context.Background()).IkeGateways(gateway).Execute()
212+
require.NoError(t, err, "Failed to create gateway for fetch test")
213+
createdGatewayID := *createRes.Id
214+
createdFolder := createRes.Folder
215+
require.NotEmpty(t, createdGatewayID, "Created gateway ID should not be empty")
216+
217+
// Defer cleanup.
218+
defer func() {
219+
t.Logf("Cleaning up IKE Gateway with ID: %s", createdGatewayID)
220+
_, errDel := client.IKEGatewaysAPI.DeleteIKEGatewaysByID(context.Background(), createdGatewayID).Execute()
221+
require.NoError(t, errDel, "Failed to delete gateway during cleanup")
222+
}()
223+
224+
// Test Fetch by name operation.
225+
fmt.Printf("Attempting to fetch IKE Gateway with name: %s\n", gatewayName)
226+
fetchedGateway, errFetch := client.IKEGatewaysAPI.FetchIKEGateways(context.Background(), gatewayName, createdFolder, nil, nil)
227+
228+
// Verify the fetch operation was successful.
229+
require.NoError(t, errFetch, "Failed to fetch gateway by name")
230+
require.NotNil(t, fetchedGateway, "Fetched gateway should not be nil")
231+
assert.Equal(t, gatewayName, fetchedGateway.Name, "Gateway name should match")
232+
assert.Equal(t, createdGatewayID, *fetchedGateway.Id, "Gateway ID should match")
233+
assert.Equal(t, *createdFolder, *fetchedGateway.Folder, "Folder should match")
234+
t.Logf("Successfully fetched IKE Gateway: %s", gatewayName)
235+
236+
// Test fetching non-existent gateway (should return nil).
237+
nonExistentName := "non-existent-ike-gateway-xyz-12345"
238+
notFoundGateway, errNotFound := client.IKEGatewaysAPI.FetchIKEGateways(context.Background(), nonExistentName, createdFolder, nil, nil)
239+
require.NoError(t, errNotFound, "Fetch for non-existent gateway should not error")
240+
assert.Nil(t, notFoundGateway, "Non-existent gateway should return nil")
241+
t.Logf("Successfully verified fetch returns nil for non-existent gateway")
242+
}
243+
198244
// Test_networkservices_IkeGatewaysAPIService_DeleteByID tests deleting an IKE Gateway.
199245
func Test_networkservices_IkeGatewaysAPIService_DeleteByID(t *testing.T) {
200246
client := SetupNetworkSvcTestClient(t)

generated/network_services/test/api_layer2_subinterface_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,49 @@ func Test_network_services_Layer2SubinterfacesAPIService_List(t *testing.T) {
300300
assert.Equal(t, http.StatusOK, httpResList.StatusCode, "Expected 200 OK status")
301301
require.NotNil(t, listRes, "List response should not be nil")
302302
}
303+
304+
// Test_network_services_Layer2SubinterfacesAPIService_Fetch tests the fetch convenience method
305+
func Test_network_services_Layer2SubinterfacesAPIService_Fetch(t *testing.T) {
306+
client := SetupNetworkSvcTestClient(t)
307+
308+
// --- 1. SETUP PREREQUISITE: Create the L2 Parent Interface ---
309+
parentIfName, parentCleanup := setupL2EthernetInterface(t, client)
310+
defer parentCleanup()
311+
312+
// Setup: Create subinterface
313+
vlanTag := "999"
314+
subIf := createFullLayer2Subinterface(t, parentIfName, vlanTag)
315+
316+
createRes, _, err := client.Layer2SubinterfacesAPI.CreateLayer2Subinterfaces(context.Background()).Layer2Subinterfaces(subIf).Execute()
317+
require.NoError(t, err, "Failed to create Layer 2 Subinterface for fetch test")
318+
createdID := *createRes.Id
319+
createdName := createRes.Name
320+
createdFolder := createRes.Folder
321+
require.NotEmpty(t, createdID, "Created subinterface ID should not be empty")
322+
323+
// Defer cleanup
324+
defer func() {
325+
t.Logf("Cleaning up Layer 2 Subinterface with ID: %s", createdID)
326+
_, errDel := client.Layer2SubinterfacesAPI.DeleteLayer2SubinterfacesByID(context.Background(), createdID).Execute()
327+
require.NoError(t, errDel, "Failed to delete subinterface during cleanup")
328+
}()
329+
330+
// Test Fetch by name operation
331+
fmt.Printf("Attempting to fetch Layer 2 Subinterface with name: %s\n", createdName)
332+
fetchedSubIf, errFetch := client.Layer2SubinterfacesAPI.FetchLayer2Subinterfaces(context.Background(), createdName, createdFolder, nil, nil)
333+
334+
// Verify the fetch operation was successful
335+
require.NoError(t, errFetch, "Failed to fetch subinterface by name")
336+
require.NotNil(t, fetchedSubIf, "Fetched subinterface should not be nil")
337+
assert.Equal(t, createdName, fetchedSubIf.Name, "Subinterface name should match")
338+
assert.Equal(t, createdID, *fetchedSubIf.Id, "Subinterface ID should match")
339+
assert.Equal(t, *createdFolder, *fetchedSubIf.Folder, "Folder should match")
340+
t.Logf("Successfully fetched Layer 2 Subinterface: %s", createdName)
341+
342+
// Test fetching non-existent subinterface (should return nil)
343+
nonExistentName := "non-existent-layer2-xyz-12345"
344+
notFoundSubIf, errNotFound := client.Layer2SubinterfacesAPI.FetchLayer2Subinterfaces(context.Background(), nonExistentName, createdFolder, nil, nil)
345+
require.NoError(t, errNotFound, "Fetch for non-existent subinterface should not error")
346+
assert.Nil(t, notFoundSubIf, "Non-existent subinterface should return nil")
347+
t.Logf("Successfully verified fetch returns nil for non-existent subinterface")
348+
}

generated/network_services/test/api_layer3_subinterface_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,52 @@ func Test_network_services_Layer3SubinterfacesAPIService_List(t *testing.T) {
329329
assert.Equal(t, http.StatusOK, httpResList.StatusCode, "Expected 200 OK status")
330330
require.NotNil(t, listRes, "List response should not be nil")
331331
}
332+
333+
// Test_network_services_Layer3SubinterfacesAPIService_Fetch tests the fetch convenience method.
334+
func Test_network_services_Layer3SubinterfacesAPIService_Fetch(t *testing.T) {
335+
client := SetupNetworkSvcTestClient(t)
336+
337+
// --- 1. SETUP PREREQUISITE: Create the L3 Parent Interface ---
338+
parentIfName, parentCleanup := setupL3EthernetInterface(t, client)
339+
defer parentCleanup()
340+
341+
// Setup: Create subinterface
342+
vlanTag := "888"
343+
subIf := createFullLayer3Subinterface(t, parentIfName, vlanTag)
344+
subIfName := subIf.GetName()
345+
346+
reqCreate := client.Layer3SubinterfacesAPI.CreateLayer3Subinterfaces(context.Background()).
347+
Layer3Subinterfaces(subIf)
348+
349+
createRes, _, err := reqCreate.Execute()
350+
require.NoError(t, err, "Failed to create Layer 3 Subinterface for fetch test")
351+
createdID := *createRes.Id
352+
createdFolder := createRes.Folder
353+
require.NotEmpty(t, createdID, "Created subinterface ID should not be empty")
354+
355+
// Defer cleanup
356+
defer func() {
357+
t.Logf("Cleaning up Layer 3 Subinterface with ID: %s", createdID)
358+
_, errDel := client.Layer3SubinterfacesAPI.DeleteLayer3SubinterfacesByID(context.Background(), createdID).Execute()
359+
require.NoError(t, errDel, "Failed to delete subinterface during cleanup")
360+
}()
361+
362+
// Test Fetch by name operation
363+
fmt.Printf("Attempting to fetch Layer 3 Subinterface with name: %s\n", subIfName)
364+
fetchedSubIf, errFetch := client.Layer3SubinterfacesAPI.FetchLayer3Subinterfaces(context.Background(), subIfName, createdFolder, nil, nil)
365+
366+
// Verify the fetch operation was successful
367+
require.NoError(t, errFetch, "Failed to fetch subinterface by name")
368+
require.NotNil(t, fetchedSubIf, "Fetched subinterface should not be nil")
369+
assert.Equal(t, subIfName, fetchedSubIf.GetName(), "Subinterface name should match")
370+
assert.Equal(t, createdID, *fetchedSubIf.Id, "Subinterface ID should match")
371+
assert.Equal(t, *createdFolder, fetchedSubIf.GetFolder(), "Folder should match")
372+
t.Logf("Successfully fetched Layer 3 Subinterface: %s", subIfName)
373+
374+
// Test fetching non-existent subinterface (should return nil)
375+
nonExistentName := "ethernet1/1.99999"
376+
notFoundSubIf, errNotFound := client.Layer3SubinterfacesAPI.FetchLayer3Subinterfaces(context.Background(), nonExistentName, createdFolder, nil, nil)
377+
require.NoError(t, errNotFound, "Fetch for non-existent subinterface should not error")
378+
assert.Nil(t, notFoundSubIf, "Non-existent subinterface should return nil")
379+
t.Logf("Successfully verified fetch returns nil for non-existent subinterface")
380+
}

generated/network_services/test/api_loopback_interface_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package network_services
88

99
import (
1010
"context"
11+
"fmt"
1112
"net/http"
1213
"testing"
1314

@@ -187,3 +188,47 @@ func Test_network_services_LoopbackInterfacesAPIService_DeleteByID(t *testing.T)
187188
require.NoError(t, errDel, "Failed to delete Loopback Interface")
188189
assert.Equal(t, http.StatusOK, httpResDel.StatusCode, "Expected 200 OK status for deletion")
189190
}
191+
192+
// Test_network_services_LoopbackInterfacesAPIService_Fetch tests the fetch convenience method.
193+
func Test_network_services_LoopbackInterfacesAPIService_Fetch(t *testing.T) {
194+
client := SetupNetworkSvcTestClient(t)
195+
196+
// Create a Loopback Interface to fetch
197+
ifName := generateLoopbackName("loopback-fetch")
198+
loopIf := createFullTestLoopbackInterface(t, ifName)
199+
200+
reqCreate := client.LoopbackInterfacesAPI.CreateLoopbackInterfaces(context.Background()).
201+
LoopbackInterfaces(loopIf)
202+
203+
createRes, _, err := reqCreate.Execute()
204+
require.NoError(t, err, "Failed to create Loopback Interface for fetch test")
205+
createdID := *createRes.Id
206+
createdFolder := createRes.Folder
207+
require.NotEmpty(t, createdID, "Created loopback interface ID should not be empty")
208+
209+
// Defer cleanup
210+
defer func() {
211+
t.Logf("Cleaning up Loopback Interface with ID: %s", createdID)
212+
_, errDel := client.LoopbackInterfacesAPI.DeleteLoopbackInterfacesByID(context.Background(), createdID).Execute()
213+
require.NoError(t, errDel, "Failed to delete loopback interface during cleanup")
214+
}()
215+
216+
// Test Fetch by name operation
217+
fmt.Printf("Attempting to fetch Loopback Interface with name: %s\n", ifName)
218+
fetchedIf, errFetch := client.LoopbackInterfacesAPI.FetchLoopbackInterfaces(context.Background(), ifName, createdFolder, nil, nil)
219+
220+
// Verify the fetch operation was successful
221+
require.NoError(t, errFetch, "Failed to fetch loopback interface by name")
222+
require.NotNil(t, fetchedIf, "Fetched loopback interface should not be nil")
223+
assert.Equal(t, ifName, fetchedIf.GetName(), "Loopback interface name should match")
224+
assert.Equal(t, createdID, *fetchedIf.Id, "Loopback interface ID should match")
225+
assert.Equal(t, *createdFolder, fetchedIf.GetFolder(), "Folder should match")
226+
t.Logf("Successfully fetched Loopback Interface: %s", ifName)
227+
228+
// Test fetching non-existent loopback interface (should return nil)
229+
nonExistentName := "loopback.99999"
230+
notFoundIf, errNotFound := client.LoopbackInterfacesAPI.FetchLoopbackInterfaces(context.Background(), nonExistentName, createdFolder, nil, nil)
231+
require.NoError(t, errNotFound, "Fetch for non-existent loopback interface should not error")
232+
assert.Nil(t, notFoundIf, "Non-existent loopback interface should return nil")
233+
t.Logf("Successfully verified fetch returns nil for non-existent loopback interface")
234+
}

generated/network_services/test/api_tunnel_interface_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package network_services
88

99
import (
1010
"context"
11+
"fmt"
1112
"net/http"
1213
"testing"
1314

@@ -195,3 +196,43 @@ func Test_network_services_TunnelInterfacesAPIService_DeleteByID(t *testing.T) {
195196
require.NoError(t, errDel, "Failed to delete Tunnel Interface")
196197
assert.Equal(t, http.StatusOK, httpResDel.StatusCode, "Expected 200 OK status for deletion")
197198
}
199+
200+
// Test_network_services_TunnelInterfacesAPIService_Fetch tests the fetch convenience method.
201+
func Test_network_services_TunnelInterfacesAPIService_Fetch(t *testing.T) {
202+
client := SetupNetworkSvcTestClient(t)
203+
interfaceName := generateTunnelName("scm-tun-fetch-")
204+
tunnelInterface := createFullTestTunnelInterface(t, interfaceName)
205+
206+
// Setup: Create an interface first
207+
createRes, _, err := client.TunnelInterfacesAPI.CreateTunnelInterfaces(context.Background()).TunnelInterfaces(tunnelInterface).Execute()
208+
require.NoError(t, err, "Failed to create interface for fetch test")
209+
createdID := *createRes.Id
210+
createdFolder := createRes.Folder
211+
require.NotEmpty(t, createdID, "Created tunnel interface ID should not be empty")
212+
213+
// Defer cleanup
214+
defer func() {
215+
t.Logf("Cleaning up Tunnel Interface with ID: %s", createdID)
216+
_, errDel := client.TunnelInterfacesAPI.DeleteTunnelInterfacesByID(context.Background(), createdID).Execute()
217+
require.NoError(t, errDel, "Failed to delete tunnel interface during cleanup")
218+
}()
219+
220+
// Test Fetch by name operation
221+
fmt.Printf("Attempting to fetch Tunnel Interface with name: %s\n", interfaceName)
222+
fetchedIf, errFetch := client.TunnelInterfacesAPI.FetchTunnelInterfaces(context.Background(), interfaceName, createdFolder, nil, nil)
223+
224+
// Verify the fetch operation was successful
225+
require.NoError(t, errFetch, "Failed to fetch tunnel interface by name")
226+
require.NotNil(t, fetchedIf, "Fetched tunnel interface should not be nil")
227+
assert.Equal(t, interfaceName, fetchedIf.GetName(), "Tunnel interface name should match")
228+
assert.Equal(t, createdID, *fetchedIf.Id, "Tunnel interface ID should match")
229+
assert.Equal(t, *createdFolder, fetchedIf.GetFolder(), "Folder should match")
230+
t.Logf("Successfully fetched Tunnel Interface: %s", interfaceName)
231+
232+
// Test fetching non-existent tunnel interface (should return nil)
233+
nonExistentName := "tunnel.99999"
234+
notFoundIf, errNotFound := client.TunnelInterfacesAPI.FetchTunnelInterfaces(context.Background(), nonExistentName, createdFolder, nil, nil)
235+
require.NoError(t, errNotFound, "Fetch for non-existent tunnel interface should not error")
236+
assert.Nil(t, notFoundIf, "Non-existent tunnel interface should return nil")
237+
t.Logf("Successfully verified fetch returns nil for non-existent tunnel interface")
238+
}

generated/network_services/test/api_vlan_interface_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,45 @@ func Test_network_services_VLANInterfacesAPIService_DeleteByID(t *testing.T) {
207207
// The API returns 200 OK for successful deletion.
208208
assert.Equal(t, http.StatusOK, httpResDel.StatusCode, "Expected 200 OK status for deletion")
209209
}
210+
211+
// Test_network_services_VLANInterfacesAPIService_Fetch tests the fetch convenience method.
212+
func Test_network_services_VLANInterfacesAPIService_Fetch(t *testing.T) {
213+
client := SetupNetworkSvcTestClient(t)
214+
215+
// Create a VLAN Interface to fetch
216+
vlanName := "$vlan-fetch-" + common.GenerateRandomString(6)
217+
vlanInterface := createFullTestVlanInterface(t, vlanName)
218+
219+
// Setup: Create an interface first
220+
createRes, _, err := client.VLANInterfacesAPI.CreateVLANInterfaces(context.Background()).VlanInterfaces(vlanInterface).Execute()
221+
require.NoError(t, err, "Failed to create interface for fetch test")
222+
createdID := *createRes.Id
223+
createdFolder := createRes.Folder
224+
require.NotEmpty(t, createdID, "Created VLAN interface ID should not be empty")
225+
226+
// Defer cleanup
227+
defer func() {
228+
t.Logf("Cleaning up VLAN Interface with ID: %s", createdID)
229+
_, errDel := client.VLANInterfacesAPI.DeleteVLANInterfacesByID(context.Background(), createdID).Execute()
230+
require.NoError(t, errDel, "Failed to delete VLAN interface during cleanup")
231+
}()
232+
233+
// Test Fetch by name operation
234+
fmt.Printf("Attempting to fetch VLAN Interface with name: %s\n", vlanName)
235+
fetchedIf, errFetch := client.VLANInterfacesAPI.FetchVLANInterfaces(context.Background(), vlanName, createdFolder, nil, nil)
236+
237+
// Verify the fetch operation was successful
238+
require.NoError(t, errFetch, "Failed to fetch VLAN interface by name")
239+
require.NotNil(t, fetchedIf, "Fetched VLAN interface should not be nil")
240+
assert.Equal(t, vlanName, fetchedIf.GetName(), "VLAN interface name should match")
241+
assert.Equal(t, createdID, *fetchedIf.Id, "VLAN interface ID should match")
242+
assert.Equal(t, *createdFolder, fetchedIf.GetFolder(), "Folder should match")
243+
t.Logf("Successfully fetched VLAN Interface: %s", vlanName)
244+
245+
// Test fetching non-existent VLAN interface (should return nil)
246+
nonExistentName := "vlan.99999"
247+
notFoundIf, errNotFound := client.VLANInterfacesAPI.FetchVLANInterfaces(context.Background(), nonExistentName, createdFolder, nil, nil)
248+
require.NoError(t, errNotFound, "Fetch for non-existent VLAN interface should not error")
249+
assert.Nil(t, notFoundIf, "Non-existent VLAN interface should return nil")
250+
t.Logf("Successfully verified fetch returns nil for non-existent VLAN interface")
251+
}

0 commit comments

Comments
 (0)