Skip to content

Commit

Permalink
atlasexec: update schema/push output
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Sep 19, 2024
1 parent 5d10c68 commit aff3fbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions atlasexec/atlas_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type (
Version string // Version of the schema to push. Defaults to the current timestamp.
Description string // Description of the schema changes.
}
// SchemaPush represents the result of a 'schema push' command.
SchemaPush struct {
URL string
Link string
}
// SchemaApplyParams are the parameters for the `schema apply` command.
SchemaApplyParams struct {
ConfigURL string
Expand Down Expand Up @@ -205,7 +210,7 @@ type (
)

// SchemaPush runs the 'schema push' command.
func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (string, error) {
func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (*SchemaPush, error) {
args := []string{"schema", "push"}
// Global flags
if params.ConfigURL != "" {
Expand All @@ -221,7 +226,7 @@ func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (stri
if params.Context != nil {
buf, err := json.Marshal(params.Context)
if err != nil {
return "", err
return nil, err
}
args = append(args, "--context", string(buf))
}
Expand All @@ -241,7 +246,7 @@ func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (stri
if params.Repo != "" {
args = append(args, params.Repo)
}
return stringVal(c.runCommand(ctx, args))
return firstResult(jsonDecode[SchemaPush](c.runCommand(ctx, args)))
}

// SchemaApply runs the 'schema apply' command.
Expand Down
5 changes: 3 additions & 2 deletions atlasexec/atlas_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,11 @@ func TestSchema_Push(t *testing.T) {
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("TEST_ARGS", tt.args)
t.Setenv("TEST_STDOUT", `https://gh.atlasgo.cloud/schemas/141733920810`)
t.Setenv("TEST_STDOUT", `{"Link":"https://gh.atlasgo.cloud/schemas/141733920810","URL":"atlas://awesome-app?tag=latest"}`)
result, err := c.SchemaPush(context.Background(), tt.params)
require.NoError(t, err)
require.Equal(t, "https://gh.atlasgo.cloud/schemas/141733920810", result)
require.Equal(t, "https://gh.atlasgo.cloud/schemas/141733920810", result.Link)
require.Equal(t, "atlas://awesome-app?tag=latest", result.URL)
})
}
}
Expand Down

0 comments on commit aff3fbf

Please sign in to comment.