Skip to content

Commit 0d44f44

Browse files
fix integration tests
1 parent 4c36e27 commit 0d44f44

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

Diff for: internal/integrationtest/core/core_test.go

+29-31
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ func TestCoreSearchNoArgs(t *testing.T) {
178178
require.Contains(t, lines, []string{"test:x86", "2.0.0", "test_core"})
179179
numPlatforms := len(lines) - 1
180180

181-
// same thing in JSON format, also check the number of platforms found is the same
181+
// Same thing in JSON format, also check the number of platforms found is the same
182182
stdout, _, err = cli.Run("core", "search", "--format", "json")
183183
require.NoError(t, err)
184184
requirejson.Contains(t, stdout, `[{"id": "test:x86", "releases": { "2.0.0": {"name":"test_core"}}}]`)
185-
requirejson.Query(t, stdout, "length", fmt.Sprint(numPlatforms))
185+
requirejson.Query(t, stdout, `[.[] | select(.latest_compatible_version != "")] | length`, fmt.Sprint(numPlatforms))
186186

187187
// list all with additional urls, check the test core is there
188188
stdout, _, err = cli.Run("core", "search", "--additional-urls="+url.String())
@@ -199,9 +199,7 @@ func TestCoreSearchNoArgs(t *testing.T) {
199199
stdout, _, err = cli.Run("core", "search", "--format", "json", "--additional-urls="+url.String())
200200
require.NoError(t, err)
201201
requirejson.Contains(t, stdout, `[{"id": "test:x86", "releases": { "3.0.0": {"name":"test_core"}}}]`)
202-
// A platform could contain multiple releases, we get the length of how many releases are present for each platform
203-
// and we sum them to see if the expected numers matches.
204-
requirejson.Query(t, stdout, `[.[].releases | length] | add`, fmt.Sprint(numPlatforms))
202+
requirejson.Query(t, stdout, `[.[] | select(.latest_compatible_version != "")] | length`, fmt.Sprint(numPlatforms))
205203
}
206204

207205
func TestCoreUpdateIndexUrlNotFound(t *testing.T) {
@@ -695,7 +693,7 @@ func TestCoreSearchSortedResults(t *testing.T) {
695693
require.NoError(t, err)
696694

697695
out := strings.Split(strings.TrimSpace(string(stdout)), "\n")
698-
var lines, deprecated, notDeprecated, incompatibles [][]string
696+
var lines, deprecated, notDeprecated [][]string
699697
for i, v := range out {
700698
if i > 0 {
701699
v = strings.Join(strings.Fields(v), " ")
@@ -707,11 +705,7 @@ func TestCoreSearchSortedResults(t *testing.T) {
707705
deprecated = append(deprecated, v)
708706
continue
709707
}
710-
if _, err := semver.Parse(v[1]); err != nil {
711-
incompatibles = append(incompatibles, v)
712-
} else {
713-
notDeprecated = append(notDeprecated, v)
714-
}
708+
notDeprecated = append(notDeprecated, v)
715709
}
716710

717711
// verify that results are already sorted correctly
@@ -721,13 +715,9 @@ func TestCoreSearchSortedResults(t *testing.T) {
721715
require.True(t, sort.SliceIsSorted(notDeprecated, func(i, j int) bool {
722716
return strings.ToLower(notDeprecated[i][2]) < strings.ToLower(notDeprecated[j][2])
723717
}))
724-
require.True(t, sort.SliceIsSorted(incompatibles, func(i, j int) bool {
725-
return strings.ToLower(incompatibles[i][2]) < strings.ToLower(incompatibles[j][2])
726-
}))
727718

728-
result := append(notDeprecated, incompatibles...)
729719
// verify that deprecated platforms are the last ones
730-
require.Equal(t, lines, append(result, deprecated...))
720+
require.Equal(t, lines, append(notDeprecated, deprecated...))
731721

732722
// test same behaviour with json output
733723
stdout, _, err = cli.Run("core", "search", "--additional-urls="+url.String(), "--format=json")
@@ -1134,15 +1124,15 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
11341124
stdout, _, err := cli.Run("core", "list", "--all", "--format", "json", additionalURLs)
11351125
require.NoError(t, err)
11361126
t.Log(string(stdout))
1137-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest`, `"1.0.2"`)
1138-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_compatible`, `"1.0.1"`)
1127+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_version`, `"1.0.2"`)
1128+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_compatible_version`, `"1.0.1"`)
11391129

11401130
// install latest compatible version
11411131
_, _, err = cli.Run("core", "install", "foo_vendor:avr", additionalURLs)
11421132
require.NoError(t, err)
11431133
stdout, _, err = cli.Run("core", "list", "--all", "--format", "json", additionalURLs)
11441134
require.NoError(t, err)
1145-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_compatible`, `"1.0.1"`)
1135+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_compatible_version`, `"1.0.1"`)
11461136

11471137
// install incompatible version
11481138
_, stderr, err := cli.Run("core", "install", "foo_vendor:[email protected]", additionalURLs)
@@ -1154,26 +1144,34 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
11541144
require.NoError(t, err)
11551145
stdout, _, err = cli.Run("core", "list", "--format", "json", additionalURLs)
11561146
require.NoError(t, err)
1157-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .installed`, `"1.0.0"`)
1147+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .installed_version`, `"1.0.0"`)
11581148

11591149
// Lists all updatable cores
11601150
stdout, _, err = cli.Run("core", "list", "--updatable", "--format", "json", additionalURLs)
11611151
require.NoError(t, err)
1162-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_compatible`, `"1.0.1"`)
1152+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_compatible_version`, `"1.0.1"`)
1153+
1154+
// Show outdated cores, must show latest compatible
1155+
stdout, _, err = cli.Run("outdated", "--format", "json", additionalURLs)
1156+
require.NoError(t, err)
1157+
requirejson.Query(t, stdout,
1158+
`.platforms | .[] | select(.id == "foo_vendor:avr") | {latest_compatible: .latest_compatible_version, latest: .latest_version}`,
1159+
`{"latest_compatible": "1.0.1", "latest": "1.0.2"}`,
1160+
)
11631161

11641162
// upgrade to latest compatible (1.0.0 -> 1.0.1)
11651163
_, _, err = cli.Run("core", "upgrade", "foo_vendor:avr", "--format", "json", additionalURLs)
11661164
require.NoError(t, err)
11671165
stdout, _, err = cli.Run("core", "list", "--format", "json", additionalURLs)
11681166
require.NoError(t, err)
1169-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .installed`, `"1.0.1"`)
1167+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .installed_version`, `"1.0.1"`)
11701168

11711169
// upgrade to latest incompatible not possible (1.0.1 -> 1.0.2)
11721170
_, _, err = cli.Run("core", "upgrade", "foo_vendor:avr", "--format", "json", additionalURLs)
11731171
require.NoError(t, err)
11741172
stdout, _, err = cli.Run("core", "list", "--format", "json", additionalURLs)
11751173
require.NoError(t, err)
1176-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .installed`, `"1.0.1"`)
1174+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .installed_version`, `"1.0.1"`)
11771175

11781176
// When no compatible version are found return error
11791177
_, stderr, err = cli.Run("core", "install", "incompatible_vendor:avr", additionalURLs)
@@ -1184,19 +1182,19 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
11841182
stdout, _, err = cli.Run("core", "search", "--all", "--format", "json", additionalURLs)
11851183
require.NoError(t, err)
11861184
requirejson.Query(t, stdout,
1187-
`[.[] | select(.id == "foo_vendor:avr") | {latest: .latest, incompatible: .incompatible}] | sort_by(.latest)`,
1185+
`[.[] | select(.id == "foo_vendor:avr") | .releases | map(.) | .[] | {version: .version, incompatible: .incompatible}] | sort_by(.version)`,
11881186
`[
1189-
{"incompatible":null,"latest":"1.0.0"},
1190-
{"incompatible":null,"latest":"1.0.1"},
1191-
{"incompatible":true,"latest":"1.0.2"}
1187+
{"incompatible":null,"version":"1.0.0"},
1188+
{"incompatible":null,"version":"1.0.1"},
1189+
{"incompatible":true,"version":"1.0.2"}
11921190
]`,
11931191
)
11941192

1195-
// Core search shows latest compatible version
1193+
// Core search shows latest compatible version even if incompatible
11961194
stdout, _, err = cli.Run("core", "search", "--format", "json", additionalURLs)
11971195
require.NoError(t, err)
1198-
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest`, `"1.0.1"`)
1199-
requirejson.Query(t, stdout, `.[] | select(.id == "incompatible_vendor:avr") | .incompatible`, `true`)
1196+
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_version`, `"1.0.2"`)
1197+
requirejson.Query(t, stdout, `.[] | select(.id == "incompatible_vendor:avr") | .releases[.latest_version].incompatible`, `true`)
12001198

12011199
// In text mode, core search doesn't show any version if no compatible one are present
12021200
stdout, _, err = cli.Run("core", "search", additionalURLs)
@@ -1205,5 +1203,5 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
12051203
for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") {
12061204
lines = append(lines, strings.Fields(strings.TrimSpace(v)))
12071205
}
1208-
require.Contains(t, lines, []string{"incompatible_vendor:avr", "Incompatible", "Boards"})
1206+
require.NotContains(t, lines, []string{"incompatible_vendor:avr"})
12091207
}

0 commit comments

Comments
 (0)