@@ -3,14 +3,14 @@ package cli_test
3
3
import (
4
4
"bytes"
5
5
"context"
6
- "io"
6
+ "crypto/sha256"
7
+ "encoding/hex"
7
8
"os"
8
9
"path/filepath"
9
10
"testing"
10
11
11
12
"github.com/codeclysm/extract"
12
13
"github.com/google/uuid"
13
- "github.com/ory/dockertest/v3/docker/pkg/archive"
14
14
"github.com/stretchr/testify/require"
15
15
16
16
"github.com/coder/coder/cli/clitest"
@@ -20,6 +20,26 @@ import (
20
20
"github.com/coder/coder/pty/ptytest"
21
21
)
22
22
23
+ // dirSum calculates a checksum of the files in a directory.
24
+ func dirSum (t * testing.T , dir string ) string {
25
+ ents , err := os .ReadDir (dir )
26
+ require .NoError (t , err )
27
+ sum := sha256 .New ()
28
+ for _ , e := range ents {
29
+ path := filepath .Join (dir , e .Name ())
30
+
31
+ stat , err := os .Stat (path )
32
+ require .NoError (t , err )
33
+
34
+ byt , err := os .ReadFile (
35
+ path ,
36
+ )
37
+ require .NoError (t , err , "mode: %+v" , stat .Mode ())
38
+ _ , _ = sum .Write (byt )
39
+ }
40
+ return hex .EncodeToString (sum .Sum (nil ))
41
+ }
42
+
23
43
func TestTemplatePull (t * testing.T ) {
24
44
t .Parallel ()
25
45
@@ -73,7 +93,6 @@ func TestTemplatePull(t *testing.T) {
73
93
// and writes it to the correct directory.
74
94
t .Run ("ToDir" , func (t * testing.T ) {
75
95
t .Parallel ()
76
- t .Skip ("FLAKE: @ammario to fix imminently" )
77
96
78
97
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
79
98
user := coderdtest .CreateFirstUser (t , client )
@@ -120,18 +139,10 @@ func TestTemplatePull(t *testing.T) {
120
139
121
140
require .NoError (t , <- errChan )
122
141
123
- expectedTarRd , err := archive .Tar (expectedDest , archive .Uncompressed )
124
- require .NoError (t , err )
125
- expectedTar , err := io .ReadAll (expectedTarRd )
126
- require .NoError (t , err )
127
-
128
- actualTarRd , err := archive .Tar (actualDest , archive .Uncompressed )
129
- require .NoError (t , err )
130
-
131
- actualTar , err := io .ReadAll (actualTarRd )
132
- require .NoError (t , err )
133
-
134
- require .True (t , bytes .Equal (expectedTar , actualTar ), "tar files differ" )
142
+ require .Equal (t ,
143
+ dirSum (t , expectedDest ),
144
+ dirSum (t , actualDest ),
145
+ )
135
146
})
136
147
137
148
// FolderConflict tests that 'templates pull' fails when a folder with has
0 commit comments