@@ -4,8 +4,10 @@ import (
4
4
"bytes"
5
5
"crypto/sha256"
6
6
"encoding/hex"
7
+ "fmt"
7
8
"io/fs"
8
9
"path/filepath"
10
+ "runtime"
9
11
"strings"
10
12
"testing"
11
13
@@ -16,6 +18,9 @@ import (
16
18
17
19
func TestGetModulesArchive (t * testing.T ) {
18
20
t .Parallel ()
21
+ if runtime .GOOS == "windows" {
22
+ t .Skip ()
23
+ }
19
24
20
25
archive , err := getModulesArchive (filepath .Join ("testdata" , "modules-source-caching" ))
21
26
require .NoError (t , err )
@@ -27,6 +32,37 @@ func TestGetModulesArchive(t *testing.T) {
27
32
require .NoError (t , err )
28
33
require .True (t , strings .HasPrefix (string (content ), "terraform {" ))
29
34
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
+
30
66
// It should always be byte-identical to optimize storage
31
67
hash := sha256 .Sum256 (archive )
32
68
require .Equal (t , "05d2994c1a50ce573fe2c2b29507e5131ba004d15812d8bb0a46dc732f3211f5" , hex .EncodeToString (hash [:]))
0 commit comments