Skip to content

Commit f23b8a8

Browse files
Migrate TestCoreSearchUpdateIndexDelay from test_core.py to core_test.go
1 parent b6a4731 commit f23b8a8

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

internal/integrationtest/core/core_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import (
1919
"crypto/md5"
2020
"encoding/hex"
2121
"fmt"
22+
"os"
2223
"runtime"
2324
"sort"
2425
"strconv"
2526
"strings"
2627
"testing"
28+
"time"
2729

2830
"github.com/arduino/arduino-cli/internal/integrationtest"
2931
"github.com/arduino/go-paths-helper"
@@ -598,6 +600,31 @@ func TestCoreListWithInstalledJson(t *testing.T) {
598600
]`)
599601
}
600602

603+
func TestCoreSearchUpdateIndexDelay(t *testing.T) {
604+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
605+
defer env.CleanUp()
606+
607+
// Verifies index update is not run
608+
stdout, _, err := cli.Run("core", "search")
609+
require.NoError(t, err)
610+
require.Contains(t, string(stdout), "Downloading index")
611+
612+
// Change edit time of package index file
613+
indexFile := cli.DataDir().Join("package_index.json")
614+
date := time.Now().Local().Add(time.Hour * (-25))
615+
require.NoError(t, os.Chtimes(indexFile.String(), date, date))
616+
617+
// Verifies index update is run
618+
stdout, _, err = cli.Run("core", "search")
619+
require.NoError(t, err)
620+
require.Contains(t, string(stdout), "Downloading index")
621+
622+
// Verifies index update is not run again
623+
stdout, _, err = cli.Run("core", "search")
624+
require.NoError(t, err)
625+
require.NotContains(t, string(stdout), "Downloading index")
626+
}
627+
601628
func TestCoreSearchSortedResults(t *testing.T) {
602629
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
603630
defer env.CleanUp()

test/test_core.py

-25
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,6 @@ def ordered(obj):
4747
assert ordered(installed_json) == ordered(expected_installed_json)
4848

4949

50-
def test_core_search_update_index_delay(run_command, data_dir):
51-
assert run_command(["update"])
52-
53-
# Verifies index update is not run
54-
res = run_command(["core", "search"])
55-
assert res.ok
56-
assert "Downloading index" not in res.stdout
57-
58-
# Change edit time of package index file
59-
index_file = Path(data_dir, "package_index.json")
60-
date = datetime.datetime.now() - datetime.timedelta(hours=25)
61-
mod_time = time.mktime(date.timetuple())
62-
os.utime(index_file, (mod_time, mod_time))
63-
64-
# Verifies index update is run
65-
res = run_command(["core", "search"])
66-
assert res.ok
67-
assert "Downloading index" in res.stdout
68-
69-
# Verifies index update is not run again
70-
res = run_command(["core", "search"])
71-
assert res.ok
72-
assert "Downloading index" not in res.stdout
73-
74-
7550
@pytest.mark.skipif(
7651
platform.system() in ["Darwin", "Windows"],
7752
reason="macOS by default is case insensitive https://github.com/actions/virtual-environments/issues/865 "

0 commit comments

Comments
 (0)