Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def try_find_resource_manager_example(
if tsp_dir:
# find example under directory
# e.g. example_path = "specification/mongocluster/DocumentDB.MongoCluster.Management/examples/2024-03-01-preview/MongoClusters_ListConnectionStrings.json"
example_paths = glob.glob(f"{path.join(specs_path, tsp_dir)}/**/{example_filename}", recursive=True)
example_paths = glob.glob(
f"{path.join(specs_path, tsp_dir)}/**/examples/{example_dir}/{example_filename}", recursive=True
)

if len(example_paths) > 0:
example_path = example_paths[0]
Expand All @@ -46,5 +48,7 @@ def try_find_resource_manager_example(
if len(candidate_resource_manager_filename) > 0:
example_path, _ = path.split(candidate_resource_manager_filename[0])
example_dir = path.relpath(example_path, specs_path).replace("\\", "/")
else:
raise RuntimeError(f"tsp-location.yaml not found in SDK package folder {sdk_package_path}")

return example_dir
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
from examples_dir import try_find_resource_manager_example


def create_mock_test_folder() -> tempfile.TemporaryDirectory:
tsp_location_file_content = """directory: specification/mongocluster/DocumentDB.MongoCluster.Management
commit: 7ed015e3dd1b8b1b0e71c9b5e6b6c5ccb8968b3a
tsp_location_file_content = """directory: specification/mongocluster/DocumentDB.MongoCluster.Management
commit: 07bdede4651ce2ea0e4039d76e81a69df23a3d6e
repo: Azure/azure-rest-api-specs
additionalDirectories: null
"""

json_example_file_content = """{
json_example_file_content = """{
"operationId": "MongoClusters_ListConnectionStrings",
"title": "List the available connection strings for the Mongo Cluster resource.",
"parameters": {
"subscriptionId": "ffffffff-ffff-ffff-ffff-ffffffffffff",
"resourceGroupName": "TestGroup",
"mongoClusterName": "myMongoCluster",
"api-version": "2024-03-01-preview"
"api-version": "2024-07-01"
},
"responses": {
"200": {
Expand All @@ -36,6 +35,8 @@ def create_mock_test_folder() -> tempfile.TemporaryDirectory:
}
"""


def create_mock_test_folder() -> tempfile.TemporaryDirectory:
tmp_path = path.abspath(".")
tmp_dir = tempfile.TemporaryDirectory(dir=tmp_path)
try:
Expand All @@ -44,6 +45,7 @@ def create_mock_test_folder() -> tempfile.TemporaryDirectory:
with open(path.join(sdk_path, "tsp-location.yaml"), "w+", encoding="utf-8") as file:
file.write(tsp_location_file_content)

# api-version 2024-03-01-preview
specs_path = path.join(
tmp_dir.name,
"azure-rest-api-specs/specification/mongocluster/DocumentDB.MongoCluster.Management/examples/2024-03-01-preview",
Expand All @@ -59,6 +61,23 @@ def create_mock_test_folder() -> tempfile.TemporaryDirectory:
makedirs(specs_path)
with open(path.join(specs_path, "MongoClusters_ListConnectionStrings.json"), "w+", encoding="utf-8") as file:
file.write(json_example_file_content)

# api-version 2024-07-01
specs_path = path.join(
tmp_dir.name,
"azure-rest-api-specs/specification/mongocluster/DocumentDB.MongoCluster.Management/examples/2024-07-01",
)
makedirs(specs_path)
with open(path.join(specs_path, "MongoClusters_ListConnectionStrings.json"), "w+", encoding="utf-8") as file:
file.write(json_example_file_content)

specs_path = path.join(
tmp_dir.name,
"azure-rest-api-specs/specification/mongocluster/resource-manager/Microsoft.DocumentDB/preview/2024-07-01/examples",
)
makedirs(specs_path)
with open(path.join(specs_path, "MongoClusters_ListConnectionStrings.json"), "w+", encoding="utf-8") as file:
file.write(json_example_file_content)
except Exception as error:
tmp_dir.cleanup()
raise error
Expand All @@ -73,15 +92,25 @@ def test_find_resource_manager_example_typespec(self):
example_dir = try_find_resource_manager_example(
path.join(tmp_dir_name, "azure-rest-api-specs"),
path.join(tmp_dir_name, "azure-sdk-for-java/sdk/mongocluster/azure-resourcemanager-mongocluster"),
"2024-03-01-preview",
"2024-07-01",
"MongoClusters_ListConnectionStrings.json",
)

self.assertEqual(
"specification/mongocluster/resource-manager/Microsoft.DocumentDB/preview/2024-03-01-preview/examples",
"specification/mongocluster/resource-manager/Microsoft.DocumentDB/preview/2024-07-01/examples",
example_dir,
)

def test_find_resource_manager_example_typespec_no_tsp_location(self):
mock_path = path.abspath(".")
with self.assertRaises(RuntimeError) as context:
example_dir = try_find_resource_manager_example(
path.join(mock_path, "azure-rest-api-specs"),
path.join(mock_path, "azure-sdk-for-java/sdk/mongocluster/azure-resourcemanager-mongocluster"),
"2024-07-01",
"MongoClusters_ListConnectionStrings.json",
)

def test_find_resource_manager_example_swagger(self):
example_dir = try_find_resource_manager_example(
"c:/github/azure-rest-api-specs",
Expand Down