Skip to content

Commit 6d971f3

Browse files
added unit test
1 parent 7e9bf94 commit 6d971f3

17 files changed

+211
-110
lines changed

tools/cli/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ list: ## List all make targets
7171
.PHONY: e2e-test
7272
e2e-test: build ## Run E2E tests
7373
@echo "==> Running E2E tests..."
74+
rm -rf test/e2e/cli/output
7475
$(TEST_CMD) -v -p 1 -parallel $(E2E_PARALLEL) -timeout $(E2E_TIMEOUT) ./test/e2e... $(E2E_EXTRA_ARGS)
7576

7677
.PHONY: gen-docs

tools/cli/internal/openapi/filter/code_sample.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ func (f *CodeSampleFilter) Apply() error {
6565
return nil
6666
}
6767

68+
func getFileExtension(format string) string {
69+
switch format {
70+
case "gzip":
71+
return "gz"
72+
default:
73+
return format
74+
}
75+
}
76+
6877
func (f *CodeSampleFilter) newDigestCurlCodeSamplesForOperation(pathName, opMethod, format string) codeSample {
6978
version := apiVersion(f.metadata.targetVersion)
7079
source := "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
@@ -75,7 +84,7 @@ func (f *CodeSampleFilter) newDigestCurlCodeSamplesForOperation(pathName, opMeth
7584
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName
7685
if format == "gzip" {
7786
source += "\" \\\n "
78-
source += "--output \"file_name." + format + "\""
87+
source += "--output \"file_name." + getFileExtension(format) + "\""
7988
} else {
8089
source += "?pretty=true\""
8190
}
@@ -105,7 +114,7 @@ func (f *CodeSampleFilter) newServiceAccountCurlCodeSamplesForOperation(pathName
105114
source += "-X " + opMethod + " \"https://cloud.mongodb.com" + pathName
106115
if format == "gzip" {
107116
source += "\" \\\n "
108-
source += "--output \"file_name." + format + "\""
117+
source += "--output \"file_name." + getFileExtension(format) + "\""
109118
} else {
110119
source += "?pretty=true\""
111120
}

tools/cli/internal/openapi/filter/code_sample_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,97 @@ func TestCodeSampleFilter(t *testing.T) {
257257
})),
258258
},
259259
},
260+
{
261+
name: "stable api gzip",
262+
version: "2025-01-01",
263+
oas: &openapi3.T{
264+
Paths: openapi3.NewPaths(openapi3.WithPath("/test", &openapi3.PathItem{
265+
Get: &openapi3.Operation{
266+
OperationID: "testOperationID",
267+
Summary: "testSummary",
268+
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
269+
Content: openapi3.Content{
270+
"application/vnd.atlas.2025-01-01+gzip": {
271+
Schema: &openapi3.SchemaRef{
272+
Ref: "#/components/schemas/PaginatedAppUserView",
273+
},
274+
Extensions: map[string]any{
275+
"x-gen-version": "2025-01-01",
276+
},
277+
},
278+
},
279+
})),
280+
Tags: []string{"TestTag"},
281+
Extensions: map[string]any{
282+
"x-sunset": "9999-12-31",
283+
},
284+
},
285+
})),
286+
},
287+
expectedOas: &openapi3.T{
288+
Paths: openapi3.NewPaths(openapi3.WithPath("/test", &openapi3.PathItem{
289+
Get: &openapi3.Operation{
290+
OperationID: "testOperationID",
291+
Summary: "testSummary",
292+
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
293+
Content: openapi3.Content{
294+
"application/vnd.atlas.2025-01-01+gzip": {
295+
Schema: &openapi3.SchemaRef{
296+
Ref: "#/components/schemas/PaginatedAppUserView",
297+
},
298+
Extensions: map[string]any{
299+
"x-gen-version": "2025-01-01",
300+
},
301+
},
302+
},
303+
})),
304+
Tags: []string{"TestTag"},
305+
Extensions: map[string]any{
306+
"x-sunset": "9999-12-31",
307+
"x-codeSamples": []codeSample{
308+
{
309+
Lang: "cURL",
310+
Label: "Atlas CLI",
311+
Source: "atlas api testOperationID --help",
312+
},
313+
{
314+
Lang: "go",
315+
Label: "Go",
316+
Source: "import (\n" +
317+
"\t\"os\"\n \"context\"\n" + "\t\"log\"\n" +
318+
"\tsdk \"go.mongodb.org/atlas-sdk/v20250101001/admin\"\n)\n\n" +
319+
"func main() {\n" +
320+
"\tctx := context.Background()\n" +
321+
"\tclientID := os.Getenv(\"MONGODB_ATLAS_CLIENT_ID\")\n" +
322+
"\tclientSecret := os.Getenv(\"MONGODB_ATLAS_CLIENT_SECRET\")\n\n" +
323+
"\t// See https://dochub.mongodb.org/core/atlas-go-sdk-oauth\n" +
324+
"\tclient, err := sdk.NewClient(sdk.UseOAuthAuth(clientID, clientSecret))\n\n" +
325+
"\tif err != nil {\n" + "\t\tlog.Fatalf(\"Error: %v\", err)\n\t}\n\n" +
326+
"\tparams = &sdk.TestOperationIDApiParams{}\n" +
327+
"\tsdkResp, httpResp, err := client.TestTagApi.\n" +
328+
"\t\tTestOperationIDWithParams(ctx, params).\n" +
329+
"\t\tExecute()" + "\n}\n",
330+
},
331+
{
332+
Lang: "cURL",
333+
Label: "curl (Service Accounts)",
334+
Source: "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n " +
335+
"--header \"Accept: application/vnd.atlas.2025-01-01+gzip\" \\\n " +
336+
"-X GET \"https://cloud.mongodb.com/test\" \\\n --output \"file_name.gz\"",
337+
},
338+
{
339+
Lang: "cURL",
340+
Label: "curl (Digest)",
341+
Source: "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n " +
342+
"--header \"Accept: application/vnd.atlas.2025-01-01+gzip\" \\\n " +
343+
"-X GET \"https://cloud.mongodb.com/test\" \\\n --output \"file_name.gz\"",
344+
},
345+
},
346+
},
347+
},
348+
})),
349+
},
350+
},
260351
}
261352

262353
for _, tt := range testCases {

tools/cli/test/data/split/dev/openapi-v2-2023-01-01.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43904,12 +43904,12 @@
4390443904
{
4390543905
"lang": "cURL",
4390643906
"label": "curl (Service Accounts)",
43907-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gzip\""
43907+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gz\""
4390843908
},
4390943909
{
4391043910
"lang": "cURL",
4391143911
"label": "curl (Digest)",
43912-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gzip\""
43912+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gz\""
4391343913
}
4391443914
]
4391543915
}
@@ -46165,12 +46165,12 @@
4616546165
{
4616646166
"lang": "cURL",
4616746167
"label": "curl (Service Accounts)",
46168-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gzip\""
46168+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gz\""
4616946169
},
4617046170
{
4617146171
"lang": "cURL",
4617246172
"label": "curl (Digest)",
46173-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gzip\""
46173+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gz\""
4617446174
}
4617546175
],
4617646176
"x-sunset": "2025-06-01"
@@ -47992,12 +47992,12 @@
4799247992
{
4799347993
"lang": "cURL",
4799447994
"label": "curl (Service Accounts)",
47995-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gzip\""
47995+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gz\""
4799647996
},
4799747997
{
4799847998
"lang": "cURL",
4799947999
"label": "curl (Digest)",
48000-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gzip\""
48000+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-01-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gz\""
4800148001
}
4800248002
]
4800348003
}

tools/cli/test/data/split/dev/openapi-v2-2023-01-01.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37472,15 +37472,15 @@ paths:
3747237472
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
3747337473
--header "Accept: application/vnd.atlas.2023-01-01+gzip" \
3747437474
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz" \
37475-
--output "file_name.gzip"
37475+
--output "file_name.gz"
3747637476
- label: curl (Digest)
3747737477
lang: cURL
3747837478
source: |-
3747937479
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
3748037480
--digest \
3748137481
--header "Accept: application/vnd.atlas.2023-01-01+gzip" \
3748237482
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz" \
37483-
--output "file_name.gzip"
37483+
--output "file_name.gz"
3748437484
/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/outageSimulation:
3748537485
delete:
3748637486
description: Ends a cluster outage simulation.
@@ -39364,15 +39364,15 @@ paths:
3936439364
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
3936539365
--header "Accept: application/vnd.atlas.2023-01-01+gzip" \
3936639366
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz" \
39367-
--output "file_name.gzip"
39367+
--output "file_name.gz"
3936839368
- label: curl (Digest)
3936939369
lang: cURL
3937039370
source: |-
3937139371
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
3937239372
--digest \
3937339373
--header "Accept: application/vnd.atlas.2023-01-01+gzip" \
3937439374
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz" \
39375-
--output "file_name.gzip"
39375+
--output "file_name.gz"
3937639376
x-sunset: "2025-06-01"
3937739377
/api/atlas/v2/groups/{groupId}/clusters/provider/regions:
3937839378
get:
@@ -41418,15 +41418,15 @@ paths:
4141841418
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
4141941419
--header "Accept: application/vnd.atlas.2023-01-01+gzip" \
4142041420
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz" \
41421-
--output "file_name.gzip"
41421+
--output "file_name.gz"
4142241422
- label: curl (Digest)
4142341423
lang: cURL
4142441424
source: |-
4142541425
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
4142641426
--digest \
4142741427
--header "Accept: application/vnd.atlas.2023-01-01+gzip" \
4142841428
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz" \
41429-
--output "file_name.gzip"
41429+
--output "file_name.gz"
4143041430
/api/atlas/v2/groups/{groupId}/databaseUsers:
4143141431
get:
4143241432
description: Returns all database users that belong to the specified project. To use this resource, the requesting API Key must have the Project Read Only role.

tools/cli/test/data/split/dev/openapi-v2-2023-02-01.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44433,12 +44433,12 @@
4443344433
{
4443444434
"lang": "cURL",
4443544435
"label": "curl (Service Accounts)",
44436-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gzip\""
44436+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gz\""
4443744437
},
4443844438
{
4443944439
"lang": "cURL",
4444044440
"label": "curl (Digest)",
44441-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gzip\""
44441+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/onlineArchives/queryLogs.gz\" \\\n --output \"file_name.gz\""
4444244442
}
4444344443
]
4444444444
}
@@ -46691,12 +46691,12 @@
4669146691
{
4669246692
"lang": "cURL",
4669346693
"label": "curl (Service Accounts)",
46694-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gzip\""
46694+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gz\""
4669546695
},
4669646696
{
4669746697
"lang": "cURL",
4669846698
"label": "curl (Digest)",
46699-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gzip\""
46699+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz\" \\\n --output \"file_name.gz\""
4670046700
}
4670146701
]
4670246702
}
@@ -48517,12 +48517,12 @@
4851748517
{
4851848518
"lang": "cURL",
4851948519
"label": "curl (Service Accounts)",
48520-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gzip\""
48520+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gz\""
4852148521
},
4852248522
{
4852348523
"lang": "cURL",
4852448524
"label": "curl (Digest)",
48525-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gzip\""
48525+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/queryLogs.gz\" \\\n --output \"file_name.gz\""
4852648526
}
4852748527
]
4852848528
}
@@ -60139,12 +60139,12 @@
6013960139
{
6014060140
"lang": "cURL",
6014160141
"label": "curl (Service Accounts)",
60142-
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/auditLogs\" \\\n --output \"file_name.gzip\""
60142+
"source": "curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/auditLogs\" \\\n --output \"file_name.gz\""
6014360143
},
6014460144
{
6014560145
"lang": "cURL",
6014660146
"label": "curl (Digest)",
60147-
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/auditLogs\" \\\n --output \"file_name.gzip\""
60147+
"source": "curl --user \"${PUBLIC_KEY}:${PRIVATE_KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2023-02-01+gzip\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/auditLogs\" \\\n --output \"file_name.gz\""
6014860148
}
6014960149
]
6015060150
}

0 commit comments

Comments
 (0)