Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64cb41a

Browse files
committed
fixed test
1 parent 6a8cf69 commit 64cb41a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

provisioner/terraform/modules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ func getModulesArchive(workdir string) ([]byte, error) {
8383
if info.IsDir() {
8484
return nil
8585
}
86-
empty = false
8786
archivePath, found := strings.CutPrefix(filePath, workdir+"/")
8887
if !found {
8988
return xerrors.Errorf("walked invalid file path: %q", filePath)
@@ -93,6 +92,7 @@ func getModulesArchive(workdir string) ([]byte, error) {
9392
if err != nil {
9493
return xerrors.Errorf("failed to read module file while archiving: %w", err)
9594
}
95+
empty = false
9696
err = w.WriteHeader(&tar.Header{
9797
Name: archivePath,
9898
Size: int64(len(content)),
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package terraform
22

33
import (
4+
"bytes"
45
"crypto/sha256"
56
"encoding/hex"
7+
"io/fs"
8+
"strings"
69
"testing"
710

11+
archivefs "github.com/coder/coder/v2/archive/fs"
812
"github.com/stretchr/testify/require"
913
)
1014

@@ -13,6 +17,16 @@ func TestGetModulesArchive(t *testing.T) {
1317

1418
archive, err := getModulesArchive("testdata/modules-source-caching")
1519
require.NoError(t, err)
20+
21+
// Check that all of the files it should contain are correct
22+
r := bytes.NewBuffer(archive)
23+
tarfs := archivefs.FromTarReader(r)
24+
content, err := fs.ReadFile(tarfs, ".terraform/modules/example_module/main.tf")
25+
require.NoError(t, err)
26+
require.True(t, strings.HasPrefix(string(content), "terraform {"))
27+
require.Len(t, content, 3691)
28+
29+
// It should always be byte-identical to optimize storage
1630
hash := sha256.Sum256(archive)
17-
require.Equal(t, "0ac7b7b3ff92d1e4bfd7ea1bef64fd7d7ac40434409fac158e383dcdd5ebeb73", hex.EncodeToString(hash[:]))
31+
require.Equal(t, "05d2994c1a50ce573fe2c2b29507e5131ba004d15812d8bb0a46dc732f3211f5", hex.EncodeToString(hash[:]))
1832
}

0 commit comments

Comments
 (0)