@@ -4,8 +4,10 @@ import (
44 "bytes"
55 "crypto/sha256"
66 "encoding/hex"
7+ "fmt"
78 "io/fs"
89 "path/filepath"
10+ "runtime"
911 "strings"
1012 "testing"
1113
@@ -16,6 +18,9 @@ import (
1618
1719func TestGetModulesArchive (t * testing.T ) {
1820 t .Parallel ()
21+ if runtime .GOOS == "windows" {
22+ t .Skip ()
23+ }
1924
2025 archive , err := getModulesArchive (filepath .Join ("testdata" , "modules-source-caching" ))
2126 require .NoError (t , err )
@@ -27,6 +32,37 @@ func TestGetModulesArchive(t *testing.T) {
2732 require .NoError (t , err )
2833 require .True (t , strings .HasPrefix (string (content ), "terraform {" ))
2934
35+ require .Len (t , content , 3691 )
36+
37+ // It should always be byte-identical to optimize storage
38+ hash := sha256 .Sum256 (archive )
39+ require .Equal (t , "05d2994c1a50ce573fe2c2b29507e5131ba004d15812d8bb0a46dc732f3211f5" , hex .EncodeToString (hash [:]))
40+ }
41+
42+ // The .tar archive is different on Windows because of git converting LF line
43+ // endings to CRLF line endings.
44+ func TestGetModulesArchiveWindows (t * testing.T ) {
45+ t .Parallel ()
46+ if runtime .GOOS != "windows" {
47+ t .Skip ()
48+ }
49+
50+ archive , err := getModulesArchive (filepath .Join ("testdata" , "modules-source-caching" ))
51+ require .NoError (t , err )
52+
53+ // debug time baby
54+ hashb := sha256 .Sum256 (archive )
55+ fmt .Println ("archive hash:" , hex .EncodeToString (hashb [:]))
56+
57+ // Check that all of the files it should contain are correct
58+ r := bytes .NewBuffer (archive )
59+ tarfs := archivefs .FromTarReader (r )
60+ content , err := fs .ReadFile (tarfs , ".terraform/modules/example_module/main.tf" )
61+ fmt .Println ("main.tf len:" , len (content ))
62+ require .NoError (t , err )
63+ require .True (t , strings .HasPrefix (string (content ), "terraform {" ))
64+ require .Len (t , content , 3691 )
65+
3066 // It should always be byte-identical to optimize storage
3167 hash := sha256 .Sum256 (archive )
3268 require .Equal (t , "05d2994c1a50ce573fe2c2b29507e5131ba004d15812d8bb0a46dc732f3211f5" , hex .EncodeToString (hash [:]))
0 commit comments