@@ -4,14 +4,6 @@ package main
44
55import (
66 "bytes"
7- "crypto/md5"
8- "encoding/hex"
9- "fmt"
10- "io"
11- "io/fs"
12- "os"
13- "path/filepath"
14- "sort"
157 "strings"
168 "time"
179
@@ -72,14 +64,12 @@ func LongTest() {
7264 sh .Cmdf ("./%s -config ../test/config.toml" , target ).Run ()
7365 })
7466 sh .InDir ("test" , func () {
75- sh .Echo ("Submitting CL and verifying depot files in both servers match..." )
67+ sh .Echo ("Submitting p4harmonize's CL..." )
68+ sh .Cmdf ("./submit.sh" ).Bash ()
69+ sh .Echo ("Verifying depot files in both servers match..." )
7670 sh .Cmdf ("./verify.sh" ).Bash ()
7771 })
7872
79- // The depot paths and types match, now let's check the file sizes and contents:
80- sh .Echo ("Comparing actual files (not just what perforce reports)..." )
81- sh .Must (compareFolderContents ("./local/p4/src" , "./local/p4/dst" ))
82- sh .Echo ("All file sizes and contents match" )
8373 sh .Echo ("***" )
8474 sh .Echo ("*** Integration Test Passed!" )
8575 sh .Echo ("***" )
@@ -92,9 +82,10 @@ func TestPrep() {
9282 sh .InDir ("test" , func () {
9383 sh .Echo ("Running test/prep.sh..." )
9484
95- // TODO: FIXME: this sleep is to avoid running prep.sh before the perforce servers are ready
96- // Ideally we'd have a test that actually confirms that the perforce servers are ready, rather
97- // then just making a race condition less likely.
85+ // TODO: FIXME: This sleep is to reduce the chance of a race condition where prep.sh runs before
86+ // the perforce servers are actually accepting connections. I've only seen this issue on linux
87+ // (which was running in Windows via VMWare), and it was inconcsistent.
88+ // Ideally there would be some check we could make here instead of just waiting and hoping.
9889 time .Sleep (time .Second )
9990
10091 sh .Cmdf ("./prep.sh" ).Bash ()
@@ -119,97 +110,3 @@ func TestDown() {
119110 sh .Cmdf ("docker compose rm -f" ).Run ()
120111 })
121112}
122-
123- // helpers
124-
125- type File struct {
126- Name string
127- Size int64
128- Hash string
129- }
130-
131- func (l File ) IsSameAs (r File ) bool {
132- return strings .ToLower (l .Name ) == strings .ToLower (r .Name ) && l .Size == r .Size && l .Hash == r .Hash
133- }
134-
135- type byNameLC []File
136-
137- func (x byNameLC ) Len () int { return len (x ) }
138- func (x byNameLC ) Less (i , j int ) bool { return strings .ToLower (x [i ].Name ) < strings .ToLower (x [j ].Name ) }
139- func (x byNameLC ) Swap (i , j int ) { x [i ], x [j ] = x [j ], x [i ] }
140-
141- func compareFolderContents (src , dst string ) error {
142- srcFiles , err := getFolderContentsSorted (src )
143- if err != nil {
144- return err
145- }
146- dstFiles , err := getFolderContentsSorted (dst )
147- if err != nil {
148- return err
149- }
150-
151- ok := len (srcFiles ) == len (dstFiles )
152- if ok {
153- for i := range srcFiles {
154- if ! srcFiles [i ].IsSameAs (dstFiles [i ]) {
155- ok = false
156- break
157- }
158- }
159- }
160-
161- if ! ok {
162- sh .Warnf ("Mismatch between src (%d) and dst (%d):" , len (srcFiles ), len (dstFiles ))
163- sh .Warn ("SOURCE:" )
164- for _ , v := range srcFiles {
165- sh .Warnf (" %v" , v )
166- }
167- sh .Warn ("DESTINATION:" )
168- for _ , v := range dstFiles {
169- sh .Warnf (" %v" , v )
170- }
171- return fmt .Errorf ("Test Failed" )
172- }
173- return nil
174- }
175-
176- func getFolderContentsSorted (root string ) ([]File , error ) {
177- cleanRoot := filepath .Clean (root )
178- var out []File
179- err := filepath .Walk (cleanRoot , func (path string , info fs.FileInfo , err error ) error {
180- if err != nil {
181- return err
182- }
183- if info .IsDir () {
184- return nil
185- }
186- hash , err := hashFile (path )
187- if err != nil {
188- return fmt .Errorf ("error hashing '%s': %w" , path , err )
189- }
190- out = append (out , File {
191- Name : strings .TrimPrefix (path , cleanRoot ),
192- Size : info .Size (),
193- Hash : hash ,
194- })
195- return nil
196- })
197- if err != nil {
198- return nil , err
199- }
200- sort .Sort (byNameLC (out ))
201- return out , err
202- }
203-
204- func hashFile (path string ) (string , error ) {
205- file , err := os .Open (path )
206- if err != nil {
207- return "" , err
208- }
209- defer file .Close ()
210- hash := md5 .New ()
211- if _ , err := io .Copy (hash , file ); err != nil {
212- return "" , err
213- }
214- return hex .EncodeToString (hash .Sum (nil )), nil
215- }
0 commit comments