@@ -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+
616643func TestCoreSearchSortedResults (t * testing.T ) {
617644 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
618645 defer env .CleanUp ()
0 commit comments