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

Check minor version and default keys to match in compatibility matrix #1063

Merged
merged 10 commits into from
Feb 3, 2023
12 changes: 0 additions & 12 deletions cmd/sql/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,12 @@ func execFlowCmd(args ...string) error {
return err
}

func execFlowCmdWrongVersion(args ...string) error {
version.CurrVersion = "foo"
cmd := NewFlowCommand()
cmd.SetArgs(args)
_, err := cmd.ExecuteC()
return err
}

func TestFlowCmd(t *testing.T) {
defer patchExecuteCmdInDocker(t, 0, nil)()
err := execFlowCmd()
assert.NoError(t, err)
}

func TestFlowCmdWrongVersion(t *testing.T) {
assert.PanicsWithError(t, "error running []: error parsing response for SQL CLI version %!w(<nil>)", func() { execFlowCmdWrongVersion() })
}

func TestFlowCmdError(t *testing.T) {
defer patchExecuteCmdInDocker(t, 0, errMock)()
err := execFlowCmd("version")
Expand Down
2 changes: 1 addition & 1 deletion sql/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const (
astroSQLCLIProjectURL = "https://pypi.org/pypi/astro-sql-cli/json"
astroSQLCLIConfigURL = "https://raw.githubusercontent.com/astronomer/astro-sdk/astro-cli/sql-cli/config/astro-cli.json"
astroSQLCLIConfigURL = "https://raw.githubusercontent.com/astronomer/astro-sdk/1673-minor-version-match/sql-cli/config/astro-cli.json"
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved
sqlCLIDockerfilePath = ".Dockerfile.sql_cli"
fileWriteMode = 0o600
sqlCLIDockerImageName = "sql_cli"
Expand Down
17 changes: 16 additions & 1 deletion sql/flow_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"regexp"
)

type configResponse struct {
Expand Down Expand Up @@ -38,6 +39,13 @@ var (

var httpClient = &http.Client{}

var semVerRegex = regexp.MustCompile("^(.*)[.](.*)[.](.*)$")
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved

const (
trimmedMinorVersionRegexMatchString = "$1.$2"
defaultVersionString = "default"
)

type AstroSQLCliVersion struct {
Version string
Prerelease bool
Expand All @@ -61,7 +69,14 @@ func GetPypiVersion(configURL, astroCliVersion string) (AstroSQLCliVersion, erro
}
SQLCliCompatibility, exists := resp.SQLCliCompatibility[astroCliVersion]
if !exists {
return AstroSQLCliVersion{}, fmt.Errorf("error parsing response for SQL CLI version %w", err)
astroCliMinorVersion := semVerRegex.ReplaceAllString(astroCliVersion, trimmedMinorVersionRegexMatchString)
SQLCliCompatibility, exists = resp.SQLCliCompatibility[astroCliMinorVersion]
if !exists {
SQLCliCompatibility, exists = resp.SQLCliCompatibility[defaultVersionString]
if !exists {
return AstroSQLCliVersion{}, fmt.Errorf("error parsing response for SQL CLI version %w", err)
}
}
}
return AstroSQLCliVersion{SQLCliCompatibility.SQLCliVersion, SQLCliCompatibility.PreRelease}, nil
}
Expand Down
17 changes: 13 additions & 4 deletions sql/flow_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ func TestGetPypiVersionInvalidHTTPRequestFailure(t *testing.T) {
assert.ErrorContains(t, err, expectedErrContains)
}

func TestGetPypiVersionInvalidAstroCliVersionFailure(t *testing.T) {
_, err := GetPypiVersion("https://raw.githubusercontent.com/astronomer/astro-sdk/astro-cli/sql-cli/config/astro-cli.json", "foo")
expectedErrContains := "error parsing response for SQL CLI version"
assert.ErrorContains(t, err, expectedErrContains)
func TestGetPypiVersionInvalidAstroCliVersionExactMatchSuccess(t *testing.T) {
_, err := GetPypiVersion("https://raw.githubusercontent.com/astronomer/astro-sdk/1673-minor-version-match/sql-cli/config/astro-cli.json", "1.9.0")
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, err)
}

func TestGetPypiVersionInvalidAstroCliVersionMinorVersionMatchSuccess(t *testing.T) {
_, err := GetPypiVersion("https://raw.githubusercontent.com/astronomer/astro-sdk/1673-minor-version-match/sql-cli/config/astro-cli.json", "1.10.1")
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, err)
}

func TestGetPypiVersionInvalidAstroCliVersionDefaultMatchSuccess(t *testing.T) {
_, err := GetPypiVersion("https://raw.githubusercontent.com/astronomer/astro-sdk/1673-minor-version-match/sql-cli/config/astro-cli.json", "x.y.z")
pankajkoti marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, err)
}

func TestGetBaseDockerImageURIInvalidURLFailure(t *testing.T) {
Expand Down