@@ -19,11 +19,13 @@ import (
19
19
"crypto/md5"
20
20
"encoding/hex"
21
21
"fmt"
22
+ "os"
22
23
"runtime"
23
24
"sort"
24
25
"strconv"
25
26
"strings"
26
27
"testing"
28
+ "time"
27
29
28
30
"github.com/arduino/arduino-cli/internal/integrationtest"
29
31
"github.com/arduino/go-paths-helper"
@@ -613,6 +615,31 @@ func TestCoreListWithInstalledJson(t *testing.T) {
613
615
]` )
614
616
}
615
617
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
+
616
643
func TestCoreSearchSortedResults (t * testing.T ) {
617
644
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
618
645
defer env .CleanUp ()
0 commit comments