Skip to content

Commit 85719ae

Browse files
Migrate TestCoreSearchUpdateIndexDelay from test_core.py to core_test.go
1 parent b65fa7c commit 85719ae

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"
@@ -613,6 +615,31 @@ func TestCoreListWithInstalledJson(t *testing.T) {
613615
]`)
614616
}
615617

618+
func TestCoreSearchUpdateIndexDelay(t *testing.T) {
619+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
620+
defer env.CleanUp()
621+
622+
// Verifies index update is not run
623+
stdout, _, err := cli.Run("core", "search")
624+
require.NoError(t, err)
625+
require.Contains(t, string(stdout), "Downloading index")
626+
627+
// Change edit time of package index file
628+
indexFile := cli.DataDir().Join("package_index.json")
629+
date := time.Now().Local().Add(time.Hour * (-25))
630+
require.NoError(t, os.Chtimes(indexFile.String(), date, date))
631+
632+
// Verifies index update is run
633+
stdout, _, err = cli.Run("core", "search")
634+
require.NoError(t, err)
635+
require.Contains(t, string(stdout), "Downloading index")
636+
637+
// Verifies index update is not run again
638+
stdout, _, err = cli.Run("core", "search")
639+
require.NoError(t, err)
640+
require.NotContains(t, string(stdout), "Downloading index")
641+
}
642+
616643
func TestCoreSearchSortedResults(t *testing.T) {
617644
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
618645
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)