fix: include subdirectories in example templates (#1715)

This commit is contained in:
David Wahler
2022-05-25 10:34:28 -05:00
committed by GitHub
parent 5492ab75c2
commit f8410dee3a
27 changed files with 91 additions and 41 deletions
+25
View File
@@ -1,6 +1,10 @@
package examples_test
import (
"archive/tar"
"bytes"
"errors"
"io"
"testing"
"github.com/stretchr/testify/require"
@@ -17,3 +21,24 @@ func TestTemplate(t *testing.T) {
_, err = examples.Archive(list[0].ID)
require.NoError(t, err)
}
func TestSubdirs(t *testing.T) {
t.Parallel()
tarData, err := examples.Archive("docker-image-builds")
require.NoError(t, err)
tarReader := tar.NewReader(bytes.NewReader(tarData))
entryPaths := make(map[byte][]string)
for {
header, err := tarReader.Next()
if errors.Is(err, io.EOF) {
break
}
require.NoError(t, err)
entryPaths[header.Typeflag] = append(entryPaths[header.Typeflag], header.Name)
}
require.Subset(t, entryPaths[tar.TypeDir], []string{"./", "images/"})
require.Subset(t, entryPaths[tar.TypeReg], []string{"README.md", "main.tf", "images/base.Dockerfile"})
}