4
4
"bytes"
5
5
"crypto/sha256"
6
6
"encoding/hex"
7
- "fmt"
8
7
"io/fs"
9
8
"path/filepath"
10
9
"runtime"
@@ -18,9 +17,6 @@ import (
18
17
19
18
func TestGetModulesArchive (t * testing.T ) {
20
19
t .Parallel ()
21
- if runtime .GOOS == "windows" {
22
- t .Skip ()
23
- }
24
20
25
21
archive , err := getModulesArchive (filepath .Join ("testdata" , "modules-source-caching" ))
26
22
require .NoError (t , err )
@@ -31,39 +27,18 @@ func TestGetModulesArchive(t *testing.T) {
31
27
content , err := fs .ReadFile (tarfs , ".terraform/modules/example_module/main.tf" )
32
28
require .NoError (t , err )
33
29
require .True (t , strings .HasPrefix (string (content ), "terraform {" ))
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
30
if runtime .GOOS != "windows" {
47
- t .Skip ()
31
+ require .Len (t , content , 3691 )
32
+ } else {
33
+ require .Len (t , content , 3812 )
48
34
}
49
35
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
-
66
36
// It should always be byte-identical to optimize storage
67
- hash := sha256 .Sum256 (archive )
68
- require .Equal (t , "05d2994c1a50ce573fe2c2b29507e5131ba004d15812d8bb0a46dc732f3211f5" , hex .EncodeToString (hash [:]))
37
+ hashBytes := sha256 .Sum256 (archive )
38
+ hash := hex .EncodeToString (hashBytes [:])
39
+ if runtime .GOOS != "windows" {
40
+ require .Equal (t , "05d2994c1a50ce573fe2c2b29507e5131ba004d15812d8bb0a46dc732f3211f5" , hash )
41
+ } else {
42
+ require .Equal (t , "0001fc95ac0ac18188931db2ef28c42f51919ee24bc18482fab38d1ea9c7a4e8" , hash )
43
+ }
69
44
}
0 commit comments