Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly parse atlas community version #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions atlasexec/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (c *Client) MigrateStatus(ctx context.Context, params *MigrateStatusParams)
return firstResult(jsonDecode[MigrateStatus](c.runCommand(ctx, args)))
}

var reVersion = regexp.MustCompile(`^atlas version v(\d+\.\d+.\d+)-?([a-z0-9]*)?`)
var reVersion = regexp.MustCompile(`^atlas( community)? version v(\d+\.\d+.\d+)-?([a-z0-9]*)?`)

// Version runs the 'version' command.
func (c *Client) Version(ctx context.Context) (*Version, error) {
Expand All @@ -551,13 +551,14 @@ func (c *Client) Version(ctx context.Context) (*Version, error) {
return nil, errors.New("unexpected output format")
}
var sha string
if len(v) > 2 {
sha = string(v[2])
if len(v) > 3 {
sha = string(v[3])
}
return &Version{
Version: string(v[1]),
SHA: sha,
Canary: strings.Contains(string(out), "canary"),
Version: string(v[2]),
SHA: sha,
Canary: strings.Contains(string(out), "canary"),
Community: strings.Contains(string(out), "community"),
}, nil
}

Expand Down
7 changes: 4 additions & 3 deletions atlasexec/atlas_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ type (
}
// Version contains the result of an 'atlas version' run.
Version struct {
Version string `json:"Version"`
SHA string `json:"SHA,omitempty"`
Canary bool `json:"Canary,omitempty"`
Version string `json:"Version"`
SHA string `json:"SHA,omitempty"`
Canary bool `json:"Canary,omitempty"`
Community bool `json:"Community,omitempty"`
}
)

Expand Down
17 changes: 14 additions & 3 deletions atlasexec/atlas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ func TestMigratePush(t *testing.T) {
require.NoError(t, err)
require.Equal(t, inputContext, p.DiffSyncDir.Input.Context)
})

})
t.Run("push", func(t *testing.T) {
tt, atlasConfigURL := newHTTPTest()
Expand Down Expand Up @@ -753,8 +752,9 @@ func TestVersion(t *testing.T) {
require.NoError(t, err)

for _, tt := range []struct {
env string
expect *atlasexec.Version
env string
community bool
expect *atlasexec.Version
}{
{
env: "",
Expand All @@ -775,8 +775,19 @@ func TestVersion(t *testing.T) {
SHA: "sha",
},
},
{
env: "v0.21.1",
community: true,
expect: &atlasexec.Version{
Version: "0.21.1",
Community: true,
},
},
} {
t.Run(tt.env, func(t *testing.T) {
if tt.community {
t.Setenv("TEST_ATLAS_COMMUNITY_EDITION", "1")
}
t.Setenv("TEST_ATLAS_VERSION", tt.env)
v, err := c.Version(context.Background())
require.NoError(t, err)
Expand Down
6 changes: 5 additions & 1 deletion atlasexec/mock-atlas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

TEST_ATLAS_VERSION="${TEST_ATLAS_VERSION:-v1.2.3}"

echo "atlas version $TEST_ATLAS_VERSION"
if [[ $TEST_ATLAS_COMMUNITY_EDITION = "1" ]]; then
echo "atlas community version $TEST_ATLAS_VERSION"
else
echo "atlas version $TEST_ATLAS_VERSION"
fi