Skip to content

Commit

Permalink
CLOUDP-297221: Add preview support to split command
Browse files Browse the repository at this point in the history
  • Loading branch information
blva committed Feb 6, 2025
1 parent 82d24b8 commit cebc24e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/cli/internal/apiversion/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"log"
"regexp"
"strings"
"time"

"github.com/getkin/kin-openapi/openapi3"
Expand Down Expand Up @@ -54,6 +55,13 @@ func New(opts ...Option) (*APIVersion, error) {
// WithVersion sets the version on the APIVersion.
func WithVersion(version string) Option {
return func(v *APIVersion) error {
if strings.EqualFold(version, PreviewStabilityLevel) {
v.version = version
v.stabilityVersion = PreviewStabilityLevel
v.versionDate = time.Now() // make preview look like the latest version
return nil
}

versionDate, err := DateFromVersion(version)
if err != nil {
return err
Expand Down Expand Up @@ -87,6 +95,7 @@ func WithContent(contentType string) Option {
v.stabilityVersion = StableStabilityLevel
if version == PreviewStabilityLevel {
v.stabilityVersion = PreviewStabilityLevel
v.versionDate = time.Now() // make preview look like the latest version
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions tools/cli/internal/apiversion/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func TestParseVersion(t *testing.T) {
expectedMatch: "2030-02-20",
wantErr: false,
},
{
name: "preview",
contentType: "application/vnd.atlas.preview+json",
expectedMatch: "preview",
wantErr: false,
},
{
name: "invalid",
contentType: "application/vnd.test.2023-01-01",
Expand Down Expand Up @@ -94,6 +100,12 @@ func TestNewAPIVersionFromContentType(t *testing.T) {
expectedMatch: "2030-02-20",
wantErr: false,
},
{
name: "preview",
contentType: "application/vnd.atlas.preview+json",
expectedMatch: "preview",
wantErr: false,
},
{
name: "invalid",
contentType: "application/vnd.test.2023-01-01",
Expand Down

0 comments on commit cebc24e

Please sign in to comment.