@@ -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"
@@ -598,6 +600,31 @@ func TestCoreListWithInstalledJson(t *testing.T) {
598
600
]` )
599
601
}
600
602
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
+
601
628
func TestCoreSearchSortedResults (t * testing.T ) {
602
629
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
603
630
defer env .CleanUp ()
0 commit comments