From 79861680bcd885b32ba465e16b9ad3b79a559a6d Mon Sep 17 00:00:00 2001 From: Bianca Lisle Date: Thu, 20 Feb 2025 18:11:09 +0000 Subject: [PATCH 1/2] chore: update script and add tests --- .github/scripts/split_spec.sh | 3 ++ .../apiversion/stabilitylevel_test.go | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tools/cli/internal/apiversion/stabilitylevel_test.go diff --git a/.github/scripts/split_spec.sh b/.github/scripts/split_spec.sh index 53ee31f7c3..68e60c7b86 100755 --- a/.github/scripts/split_spec.sh +++ b/.github/scripts/split_spec.sh @@ -12,5 +12,8 @@ mv -f "openapi-foas.json" "./openapi/v2.json" foascli split -s openapi-foas.yaml --env "${target_env:?}" -o ./openapi/v2/openapi.yaml mv -f "openapi-foas.yaml" "./openapi/v2.yaml" +# Create folder if it does not exist +mkdir -p ./openapi/private + echo "Moving preview files to preview and private-preview folder" find ./openapi/v2 -type f -name "*private-preview*" -exec mv -f {} ./openapi/private/ \; diff --git a/tools/cli/internal/apiversion/stabilitylevel_test.go b/tools/cli/internal/apiversion/stabilitylevel_test.go new file mode 100644 index 0000000000..7ef88f3702 --- /dev/null +++ b/tools/cli/internal/apiversion/stabilitylevel_test.go @@ -0,0 +1,50 @@ +package apiversion + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestIsPreviewSabilityLevel(t *testing.T) { + assert.True(t, IsPreviewSabilityLevel("preview")) + assert.True(t, IsPreviewSabilityLevel("PREVIEW")) + assert.True(t, IsPreviewSabilityLevel("prEvIEW")) + assert.True(t, IsPreviewSabilityLevel("private-preview")) + assert.True(t, IsPreviewSabilityLevel("public-preview")) + assert.False(t, IsPreviewSabilityLevel("stable")) + assert.False(t, IsPreviewSabilityLevel("invalid")) +} + +func TestIsPrivatePreviewSabilityLevel(t *testing.T) { + assert.True(t, IsPrivatePreviewSabilityLevel("private-preview")) + assert.False(t, IsPrivatePreviewSabilityLevel("public-preview")) + assert.False(t, IsPrivatePreviewSabilityLevel("preview")) + assert.False(t, IsPrivatePreviewSabilityLevel("stable")) + assert.False(t, IsPrivatePreviewSabilityLevel("invalid")) +} + +func TestIsPublicPreviewSabilityLevel(t *testing.T) { + assert.True(t, IsPublicPreviewSabilityLevel("public-preview")) + assert.True(t, IsPublicPreviewSabilityLevel("preview")) + assert.False(t, IsPublicPreviewSabilityLevel("private-preview")) + assert.False(t, IsPublicPreviewSabilityLevel("stable")) + assert.False(t, IsPublicPreviewSabilityLevel("invalid")) +} + +func TestIsStableSabilityLevel(t *testing.T) { + assert.True(t, IsStableSabilityLevel("stable")) + assert.False(t, IsStableSabilityLevel("preview")) + assert.False(t, IsStableSabilityLevel("private-preview")) + assert.False(t, IsStableSabilityLevel("public-preview")) + assert.False(t, IsStableSabilityLevel("invalid")) +} + +func TestValidateStabilityLevel(t *testing.T) { + require.NoError(t, ValidateStabilityLevel("stable")) + require.NoError(t, ValidateStabilityLevel("preview")) + require.NoError(t, ValidateStabilityLevel("private-preview")) + require.NoError(t, ValidateStabilityLevel("public-preview")) + assert.Error(t, ValidateStabilityLevel("invalid")) +} From e073719d51726948eaf2ad3c45cd1a3a1937c99f Mon Sep 17 00:00:00 2001 From: Bianca Lisle Date: Thu, 20 Feb 2025 18:13:27 +0000 Subject: [PATCH 2/2] Update to also collect preview --- .github/scripts/split_spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/split_spec.sh b/.github/scripts/split_spec.sh index 68e60c7b86..f55dafb5f3 100755 --- a/.github/scripts/split_spec.sh +++ b/.github/scripts/split_spec.sh @@ -2,7 +2,7 @@ set -eou pipefail echo "Running FOAS CLI versions command" -foascli versions -s openapi-foas.json -o ./openapi/v2/versions.json --env "${target_env:?}" --stability-level stable +foascli versions -s openapi-foas.json -o ./openapi/v2/versions.json --env "${target_env:?}" --stability-level stable --stability-level preview echo "Running FOAS CLI split command with the following --env=${target_env:?} and -o=./openapi/v2/openapi.json"