Skip to content

Commit

Permalink
wip: fix 'core' integrationtests
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Oct 11, 2023
1 parent b3e43f1 commit dad84a9
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCorrectHandlingOfPlatformVersionProperty(t *testing.T) {
// Trigger problematic call
out, _, err := cli.Run("core", "list", "--format", "json")
require.NoError(t, err)
requirejson.Contains(t, out, `[{"id":"DxCore-dev:megaavr","installed":"1.4.10","name":"DxCore"}]`)
requirejson.Contains(t, out, `[{"id":"DxCore-dev:megaavr","installed_version":"1.4.10","name":"DxCore"}]`)
}

func TestCoreSearch(t *testing.T) {
Expand All @@ -73,8 +73,8 @@ func TestCoreSearch(t *testing.T) {
out, _, err = cli.Run("core", "search", "avr", "--format", "json")
require.NoError(t, err)
requirejson.NotEmpty(t, out)
// Verify that "installed" is set
requirejson.Contains(t, out, `[{installed: "1.8.6"}]`)
// Verify that "installed_version" is set
requirejson.Contains(t, out, `[{installed_version: "1.8.6"}]`)

// additional URL
out, _, err = cli.Run("core", "search", "test_core", "--format", "json", "--additional-urls="+url.String())
Expand All @@ -84,10 +84,10 @@ func TestCoreSearch(t *testing.T) {
// show all versions
out, _, err = cli.Run("core", "search", "test_core", "--all", "--format", "json", "--additional-urls="+url.String())
require.NoError(t, err)
requirejson.Len(t, out, 3)
requirejson.Query(t, out, `.[].releases | length`, "3")

checkPlatformIsInJSONOutput := func(stdout []byte, id, version string) {
jqquery := fmt.Sprintf(`[{id:"%s", latest:"%s"}]`, id, version)
jqquery := fmt.Sprintf(`[{id:"%s", releases:{"%s":{}}}]`, id, version)
requirejson.Contains(t, out, jqquery, "platform %s@%s is missing from the output", id, version)
}

Expand Down Expand Up @@ -171,7 +171,7 @@ func TestCoreSearchNoArgs(t *testing.T) {
// same thing in JSON format, also check the number of platforms found is the same
stdout, _, err = cli.Run("core", "search", "--format", "json")
require.NoError(t, err)
requirejson.Contains(t, stdout, `[ { "name":"test_core" } ]`)
requirejson.Contains(t, stdout, `[{"id": "test:x86", "releases": { "2.0.0": {"name":"test_core"}}}]`)
requirejson.Query(t, stdout, "length", fmt.Sprint(numPlatforms))

// list all with additional urls, check the test core is there
Expand All @@ -188,8 +188,8 @@ func TestCoreSearchNoArgs(t *testing.T) {
// same thing in JSON format, also check the number of platforms found is the same
stdout, _, err = cli.Run("core", "search", "--format", "json", "--additional-urls="+url.String())
require.NoError(t, err)
requirejson.Contains(t, stdout, `[ { "name":"test_core" } ]`)
requirejson.Query(t, stdout, "length", fmt.Sprint(numPlatforms))
requirejson.Contains(t, stdout, `[{"id": "test:x86", "releases": { "3.0.0": {"name":"test_core"}}}]`)
requirejson.Query(t, stdout, `[.[].releases | length] | add`, fmt.Sprint(numPlatforms))
}

func TestCoreUpdateIndexUrlNotFound(t *testing.T) {
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestCoreInstall(t *testing.T) {
require.NoError(t, err)
stdout, _, err := cli.Run("core", "list", "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, `.[] | select(.id == "arduino:avr") | .installed`, `"1.6.16"`)
requirejson.Query(t, stdout, `.[] | select(.id == "arduino:avr") | .installed_version`, `"1.6.16"`)

// Replace it with the same with --no-overwrite (should NOT fail)
_, _, err = cli.Run("core", "install", "arduino:[email protected]", "--no-overwrite")
Expand All @@ -318,22 +318,22 @@ func TestCoreInstall(t *testing.T) {
require.NoError(t, err)
stdout, _, err = cli.Run("core", "list", "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, `.[] | select(.id == "arduino:avr") | .installed`, `"1.6.17"`)
requirejson.Query(t, stdout, `.[] | select(.id == "arduino:avr") | .installed_version`, `"1.6.17"`)

// Confirm core is listed as "updatable"
stdout, _, err = cli.Run("core", "list", "--updatable", "--format", "json")
require.NoError(t, err)
jsonout := requirejson.Parse(t, stdout)
q := jsonout.Query(`.[] | select(.id == "arduino:avr")`)
q.Query(".installed").MustEqual(`"1.6.17"`)
latest := q.Query(".latest")
q.Query(".installed_version").MustEqual(`"1.6.17"`)
latest := q.Query(".latest_version")

// Upgrade the core to latest version
_, _, err = cli.Run("core", "upgrade", "arduino:avr")
require.NoError(t, err)
stdout, _, err = cli.Run("core", "list", "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, `.[] | select(.id == "arduino:avr") | .installed`, latest.String())
requirejson.Query(t, stdout, `.[] | select(.id == "arduino:avr") | .installed_version`, latest.String())

// double check the core isn't updatable anymore
stdout, _, err = cli.Run("core", "list", "--updatable", "--format", "json")
Expand Down Expand Up @@ -483,10 +483,14 @@ func TestCoreListAllManuallyInstalledCore(t *testing.T) {
requirejson.Contains(t, stdout, `[
{
"id": "arduino-beta-development:avr",
"latest": "1.8.3",
"name": "Arduino AVR Boards"
"latest_version": "1.8.3",
"releases": {
"1.8.3": {
"name": "Arduino AVR Boards"
}
}
]`)
}
]`)
}

func TestCoreListUpdatableAllFlags(t *testing.T) {
Expand Down Expand Up @@ -519,10 +523,14 @@ func TestCoreListUpdatableAllFlags(t *testing.T) {
requirejson.Contains(t, stdout, `[
{
"id": "arduino-beta-development:avr",
"latest": "1.8.3",
"name": "Arduino AVR Boards"
"latest_version": "1.8.3",
"releases": {
"1.8.3": {
"name": "Arduino AVR Boards"
}
}
]`)
}
]`)
}

func TestCoreUpgradeRemovesUnusedTools(t *testing.T) {
Expand Down Expand Up @@ -592,7 +600,11 @@ func TestCoreListWithInstalledJson(t *testing.T) {
requirejson.Contains(t, stdout, `[
{
"id": "adafruit:avr",
"name": "Adafruit AVR Boards"
"releases": {
"1.4.13": {
"name": "Adafruit AVR Boards"
}
}
}
]`)

Expand All @@ -614,7 +626,11 @@ func TestCoreListWithInstalledJson(t *testing.T) {
requirejson.Contains(t, stdout, `[
{
"id": "adafruit:avr",
"name": "Adafruit Boards"
"releases": {
"1.4.13": {
"name": "Adafruit Boards"
}
}
}
]`)
}
Expand Down Expand Up @@ -940,10 +956,10 @@ func TestCoreListOutdatedCore(t *testing.T) {
stdout, _, err := cli.Run("core", "list", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, stdout, 1)
requirejson.Query(t, stdout, ".[0] | .installed", "\"1.8.6\"")
installedVersion, err := semver.Parse(strings.Trim(requirejson.Parse(t, stdout).Query(".[0] | .installed").String(), "\""))
requirejson.Query(t, stdout, ".[0] | .installed_version", "\"1.8.6\"")
installedVersion, err := semver.Parse(strings.Trim(requirejson.Parse(t, stdout).Query(".[0] | .installed_version").String(), "\""))
require.NoError(t, err)
latestVersion, err := semver.Parse(strings.Trim(requirejson.Parse(t, stdout).Query(".[0] | .latest").String(), "\""))
latestVersion, err := semver.Parse(strings.Trim(requirejson.Parse(t, stdout).Query(".[0] | .latest_version").String(), "\""))
require.NoError(t, err)
// Installed version must be older than latest
require.True(t, installedVersion.LessThan(latestVersion))
Expand Down

0 comments on commit dad84a9

Please sign in to comment.