Skip to content

Commit 2d1d321

Browse files
committed
re-doing commit
1 parent 180061d commit 2d1d321

File tree

16 files changed

+205
-739
lines changed

16 files changed

+205
-739
lines changed

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/go.imports.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scm-go.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/config_setup/test/api_folders_test.go

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -197,58 +197,20 @@ func Test_config_setup_FoldersAPIService_Update(t *testing.T) {
197197

198198
// ---
199199

200-
// Test_config_setup_FoldersAPIService_List tests listing folders
200+
// Test_config_setup_FoldersAPIService_List tests listing folders (read-only)
201201
func Test_config_setup_FoldersAPIService_List(t *testing.T) {
202-
t.Skip("API returns 500 Internal Server Error on folder create - folder creation not supported in test environment")
203202
// Setup the authenticated client
204203
client := SetupConfigSvcTestClient(t)
205204

206-
// 1. Create a folder first to have something to list
207-
createdFolderName := "test-folder-list-" + common.GenerateRandomString(10)
208-
folder := config_setup.Folders{
209-
Description: common.StringPtr("Test folder for list API testing"),
210-
Name: createdFolderName,
211-
Parent: "Shared",
212-
}
213-
214-
// Create the folder via API
215-
reqCreate := client.FoldersAPI.CreateFolder(context.Background()).Folders(folder)
216-
createRes, _, err := reqCreate.Execute()
217-
if err != nil {
218-
handleAPIError(err)
219-
}
220-
require.NoError(t, err, "Failed to create folder for list test")
221-
createdFolderID := createRes.Id
222-
require.NotEmpty(t, createdFolderID, "Created folder should have an ID")
223-
224-
// 2. Test List operation
225-
reqList := client.FoldersAPI.ListFolders(context.Background()).Limit(500)
226-
listRes, httpResList, errList := reqList.Execute()
205+
// Read-only test: list existing folders (Create gives 500, but List works independently)
206+
listRes, httpResList, errList := client.FoldersAPI.ListFolders(context.Background()).Limit(200).Offset(0).Execute()
227207
if errList != nil {
228208
handleAPIError(errList)
229209
}
230-
231-
// Verify the list operation was successful
232210
require.NoError(t, errList, "Failed to list folders")
233211
assert.Equal(t, 200, httpResList.StatusCode, "Expected 200 OK status")
234-
235-
// Assert response object properties
236212
require.NotNil(t, listRes, "List response should not be nil")
237-
require.NotNil(t, listRes.Data, "List response data should not be nil")
238-
assert.GreaterOrEqual(t, len(listRes.Data), 1, "Expected at least 1 folder in the list response")
239-
240-
t.Logf("Successfully listed and found created folder: %s", createdFolderName)
241-
242-
// 3. Cleanup: Delete the created folder
243-
reqDel := client.FoldersAPI.DeleteFolderByID(context.Background(), createdFolderID)
244-
httpResDel, errDel := reqDel.Execute()
245-
if errDel != nil {
246-
handleAPIError(errDel)
247-
}
248-
require.NoError(t, errDel, "Failed to delete folder during cleanup")
249-
assert.Equal(t, 200, httpResDel.StatusCode, "Expected 200 OK status for delete")
250-
251-
t.Logf("Successfully cleaned up folder: %s", createdFolderID)
213+
t.Logf("Successfully listed folders, total: %d", listRes.GetTotal())
252214
}
253215

254216
// ---
@@ -299,60 +261,19 @@ func Test_config_setup_FoldersAPIService_DeleteByID(t *testing.T) {
299261
assert.Equal(t, 404, httpResGet.StatusCode, "Expected 404 Not Found status after deletion")
300262
}
301263

302-
// Test_config_setup_FoldersAPIService_FetchFolders tests the FetchFolders convenience method
264+
// Test_config_setup_FoldersAPIService_FetchFolders tests the FetchFolders convenience method (read-only)
303265
func Test_config_setup_FoldersAPIService_FetchFolders(t *testing.T) {
304-
t.Skip("API returns 500 Internal Server Error on folder create - folder creation not supported in test environment")
305266
// Setup the authenticated client
306267
client := SetupConfigSvcTestClient(t)
307268

308-
// Create test object using same payload as Create test
309-
testName := "test-folder-fetch-" + common.GenerateRandomString(6)
310-
testObj := config_setup.Folders{
311-
Description: common.StringPtr("Test folder for fetch API testing"),
312-
Name: testName,
313-
Parent: "Shared",
314-
}
315-
316-
createReq := client.FoldersAPI.CreateFolder(context.Background()).Folders(testObj)
317-
createRes, _, err := createReq.Execute()
318-
if err != nil {
319-
handleAPIError(err)
320-
}
321-
require.NoError(t, err, "Failed to create test object for fetch test")
322-
require.NotNil(t, createRes, "Create response should not be nil")
323-
createdID := createRes.Id
324-
325-
// Cleanup after test
326-
defer func() {
327-
deleteReq := client.FoldersAPI.DeleteFolderByID(context.Background(), createdID)
328-
_, _ = deleteReq.Execute()
329-
t.Logf("Cleaned up test object: %s", createdID)
330-
}()
331-
332-
// Test 1: Fetch existing object by name
333-
fetchedObj, err := client.FoldersAPI.FetchFolders(
269+
// Read-only test: Fetch non-existent object (should return nil, nil)
270+
notFound, err := client.FoldersAPI.FetchFolders(
334271
context.Background(),
335-
testName,
336-
nil, // folder (folders don't have folder field)
272+
"non-existent-folder-xyz-12345",
273+
nil, // folder
337274
nil, // snippet
338275
nil, // device
339276
)
340-
341-
// Verify successful fetch
342-
require.NoError(t, err, "Failed to fetch folders by name")
343-
require.NotNil(t, fetchedObj, "Fetched object should not be nil")
344-
assert.Equal(t, createdID, fetchedObj.Id, "Fetched object ID should match")
345-
assert.Equal(t, testName, fetchedObj.Name, "Fetched object name should match")
346-
t.Logf("[SUCCESS] FetchFolders found object: %s", fetchedObj.Name)
347-
348-
// Test 2: Fetch non-existent object (should return nil, nil)
349-
notFound, err := client.FoldersAPI.FetchFolders(
350-
context.Background(),
351-
"non-existent-folders-xyz-12345",
352-
nil, // folder (folders don't have folder field)
353-
nil,
354-
nil,
355-
)
356277
require.NoError(t, err, "Fetch should not error for non-existent object")
357278
assert.Nil(t, notFound, "Should return nil for non-existent object")
358279
t.Logf("[SUCCESS] FetchFolders correctly returned nil for non-existent object")

generated/deployment_services/test/api_sites_test.go

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -128,42 +128,18 @@ func Test_deployment_services_SitesAPIService_Update(t *testing.T) {
128128
assert.Equal(t, "123 Updated Street", *updateRes.AddressLine1, "Address should be updated")
129129
}
130130

131-
// Test_deployment_services_SitesAPIService_List tests listing Sites.
131+
// Test_deployment_services_SitesAPIService_List tests listing Sites (read-only).
132132
func Test_deployment_services_SitesAPIService_List(t *testing.T) {
133-
t.Skip("Skipping test: Sites model has non-pointer Id field (Id string), which causes issues with object creation as the API populates this field")
134-
135-
depSvcClient := SetupDeploymentSvcTestClient(t)
136-
randomSuffix := common.GenerateRandomString(6)
133+
client := SetupDeploymentSvcTestClient(t)
137134

138-
// Create a site to ensure it appears in the list.
139-
siteName := "test-site-list-" + randomSuffix
140-
site := deployment_services.Sites{
141-
Name: siteName,
142-
Id: "", // Will be populated by API
135+
listRes, httpResList, errList := client.SitesAPI.ListSites(context.Background()).Folder("All").Limit(200).Offset(0).Execute()
136+
if errList != nil {
137+
handleAPIError(errList)
143138
}
144-
createRes, _, err := depSvcClient.SitesAPI.CreateSites(context.Background()).Sites(site).Execute()
145-
require.NoError(t, err, "Failed to create site for list test")
146-
createdSiteID := createRes.Id
147-
defer func() {
148-
depSvcClient.SitesAPI.DeleteSitesByID(context.Background(), createdSiteID).Execute()
149-
}()
150-
151-
// Test List operation.
152-
// Note: Sites API requires folder parameter
153-
listRes, httpResList, errList := depSvcClient.SitesAPI.ListSites(context.Background()).Folder("All").Limit(10000).Execute()
154139
require.NoError(t, errList, "Failed to list sites")
155-
assert.Equal(t, 200, httpResList.StatusCode)
156-
require.NotNil(t, listRes)
157-
158-
// Verify our created site is in the list.
159-
foundSite := false
160-
for _, s := range listRes.Data {
161-
if s.Name == siteName {
162-
foundSite = true
163-
break
164-
}
165-
}
166-
assert.True(t, foundSite, "Created site should be found in the list")
140+
assert.Equal(t, 200, httpResList.StatusCode, "Expected 200 OK status")
141+
require.NotNil(t, listRes, "List response should not be nil")
142+
t.Logf("Successfully listed sites, total: %d", listRes.GetTotal())
167143
}
168144

169145
// Test_deployment_services_SitesAPIService_DeleteByID tests deleting a site by ID.
@@ -188,58 +164,13 @@ func Test_deployment_services_SitesAPIService_DeleteByID(t *testing.T) {
188164
require.NoError(t, errDel, "Failed to delete site")
189165
}
190166

191-
// Test_deployment_services_SitesAPIService_FetchSites tests the FetchSites convenience method
167+
// Test_deployment_services_SitesAPIService_FetchSites tests the FetchSites convenience method (read-only).
192168
func Test_deployment_services_SitesAPIService_FetchSites(t *testing.T) {
193-
t.Skip("Skipping test: Sites model has non-pointer Id field (Id string), which causes issues with object creation as the API populates this field")
194-
195-
// Setup the authenticated client
196169
client := SetupDeploymentSvcTestClient(t)
197170

198-
// Create test object using same payload as Create test
199-
randomSuffix := common.GenerateRandomString(6)
200-
testName := "test-site-fetch-" + randomSuffix
201-
202-
testObj := deployment_services.Sites{
203-
Name: testName,
204-
Id: "", // Will be populated by API
205-
}
206-
207-
createReq := client.SitesAPI.CreateSites(context.Background()).Sites(testObj)
208-
createRes, _, err := createReq.Execute()
209-
if err != nil {
210-
handleAPIError(err)
211-
}
212-
require.NoError(t, err, "Failed to create test object for fetch test")
213-
require.NotNil(t, createRes, "Create response should not be nil")
214-
createdID := createRes.Id
215-
216-
// Cleanup after test
217-
defer func() {
218-
deleteReq := client.SitesAPI.DeleteSitesByID(context.Background(), createdID)
219-
_, _ = deleteReq.Execute()
220-
t.Logf("Cleaned up test object: %s", createdID)
221-
}()
222-
223-
// Test 1: Fetch existing object by name
224-
fetchedObj, err := client.SitesAPI.FetchSites(
225-
context.Background(),
226-
testName,
227-
common.StringPtr("All"),
228-
nil, // snippet
229-
nil, // device
230-
)
231-
232-
// Verify successful fetch
233-
require.NoError(t, err, "Failed to fetch sites by name")
234-
require.NotNil(t, fetchedObj, "Fetched object should not be nil")
235-
assert.Equal(t, createdID, fetchedObj.Id, "Fetched object ID should match")
236-
assert.Equal(t, testName, fetchedObj.Name, "Fetched object name should match")
237-
t.Logf("[SUCCESS] FetchSites found object: %s", fetchedObj.Name)
238-
239-
// Test 2: Fetch non-existent object (should return nil, nil)
240171
notFound, err := client.SitesAPI.FetchSites(
241172
context.Background(),
242-
"non-existent-sites-xyz-12345",
173+
"non-existent-site-xyz-12345",
243174
common.StringPtr("All"),
244175
nil,
245176
nil,

generated/identity_services/test/api_certificates_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@ Identity Services Testing CertificatesAPIService
44
package identity_services
55

66
import (
7+
"context"
78
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
13+
"github.com/paloaltonetworks/scm-go/common"
814
)
915

1016
// Test_identity_services_CertificatesAPIService_FetchCertificates tests the FetchCertificates convenience method
1117
func Test_identity_services_CertificatesAPIService_FetchCertificates(t *testing.T) {
12-
// Note: Certificates API requires an existing CA (Certificate Authority) to sign new certificates.
13-
// The 'signed_by' field must reference an existing CA name from TrustedCertificateAuthorities.
14-
// Without a standardized/guaranteed CA name across environments, this test cannot reliably run.
15-
// Python SDK (scm-python) also does not include tests for this API for the same reason.
16-
t.Skip("Certificates API requires existing CA infrastructure - no standard CA name available across environments")
18+
client := SetupIdentitySvcTestClient(t)
19+
20+
// Test: Fetch non-existent object (should return nil, nil)
21+
// Cannot test positive path because Create requires existing CA infrastructure
22+
notFound, err := client.CertificatesAPI.FetchCertificates(
23+
context.Background(),
24+
"non-existent-cert-xyz-12345",
25+
common.StringPtr("Prisma Access"),
26+
nil,
27+
nil,
28+
)
29+
require.NoError(t, err, "Fetch should not error for non-existent object")
30+
assert.Nil(t, notFound, "Should return nil for non-existent object")
31+
t.Logf("[SUCCESS] FetchCertificates correctly returned nil for non-existent object")
1732
}

0 commit comments

Comments
 (0)