diff --git a/.github/scripts/split_spec.sh b/.github/scripts/split_spec.sh index 53ee31f7c3..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" @@ -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")) +}