-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdockerfmt_test.go
50 lines (45 loc) · 1.32 KB
/
dockerfmt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"path/filepath"
"strings"
"testing"
"github.com/reteps/dockerfmt/lib"
"github.com/stretchr/testify/assert"
)
func TestFormatter(t *testing.T) {
// assert equality
assert.Equal(t, 123, 123, "they should be equal")
matchingFiles, err := filepath.Glob("tests/in/*.dockerfile")
if err != nil {
t.Fatalf("Failed to find test files: %v", err)
}
c := &lib.Config{
IndentSize: 4,
TrailingNewline: true,
SpaceRedirects: false,
}
for _, fileName := range matchingFiles {
t.Run(fileName, func(t *testing.T) {
outFile := strings.Replace(fileName, "in", "out", 1)
originalLines, err := lib.GetFileLines(fileName)
if err != nil {
t.Fatalf("Failed to read file %s: %v", fileName, err)
}
fmt.Printf("Comparing file %s with %s\n", fileName, outFile)
formattedLines := lib.FormatFileLines(originalLines, c)
// Write outFile to directory
// err = os.WriteFile(outFile, []byte(formattedLines), 0644)
// if err != nil {
// t.Fatalf("Failed to write to file %s: %v", outFile, err)
// }
// Read outFile
outLines, err := lib.GetFileLines(outFile)
if err != nil {
t.Fatalf("Failed to read file %s: %v", outFile, err)
}
// Compare outLines with formattedLines
assert.Equal(t, strings.Join(outLines, ""), formattedLines, "Files should be equal")
})
}
}