16
16
package lib_test
17
17
18
18
import (
19
+ "crypto/sha256"
20
+ "encoding/hex"
19
21
"encoding/json"
20
22
"fmt"
21
23
"io"
@@ -687,6 +689,7 @@ func TestInstallWithGitUrlFragmentAsBranch(t *testing.T) {
687
689
688
690
t .Run ("RefPointingToBranch" , func (t * testing.T ) {
689
691
libInstallDir := cli .SketchbookDir ().Join ("libraries" , "ArduinoCloud" )
692
+ t .Cleanup (func () { libInstallDir .RemoveAll () })
690
693
691
694
// Verify install with ref pointing to a branch
692
695
require .NoDirExists (t , libInstallDir .String ())
@@ -700,6 +703,24 @@ func TestInstallWithGitUrlFragmentAsBranch(t *testing.T) {
700
703
require .NoError (t , err )
701
704
require .Contains (t , string (fileToTest ), `#define LENGHT_M "meters"` ) // nolint:misspell
702
705
})
706
+
707
+ t .Run ("RefPointingToHash" , func (t * testing.T ) {
708
+ libInstallDir := cli .SketchbookDir ().Join ("libraries" , "ArduinoCloud" )
709
+ t .Cleanup (func () { libInstallDir .RemoveAll () })
710
+
711
+ // Verify install with ref pointing to a branch
712
+ require .NoDirExists (t , libInstallDir .String ())
713
+ _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , "https://github.com/arduino-libraries/ArduinoCloud.git#fe1a1c5d1f8ea2cb27ece1a3b9344dc1eaed60b6" , "--config-file" , "arduino-cli.yaml" )
714
+ require .NoError (t , err )
715
+ require .DirExists (t , libInstallDir .String ())
716
+
717
+ // Verify that the correct branch is checked out
718
+ // https://github.com/arduino-libraries/ArduinoCloud/commit/fe1a1c5d1f8ea2cb27ece1a3b9344dc1eaed60b6
719
+ fileToTest , err := libInstallDir .Join ("examples" , "ReadAndWrite" , "ReadAndWrite.ino" ).ReadFile ()
720
+ require .NoError (t , err )
721
+ chksum := sha256 .Sum256 (fileToTest )
722
+ require .Equal (t , hex .EncodeToString (chksum [:]), `f71889cd6da3b91755c7d1b8ec76b7ee6e2824d8a417c043d117ffdf1546f896` )
723
+ })
703
724
}
704
725
705
726
func TestUpdateIndex (t * testing.T ) {
0 commit comments