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