fix: flake in template pull (#6317)

This commit is contained in:
Ammar Bandukwala
2023-02-22 22:59:07 -06:00
committed by GitHub
parent f6a8c360e5
commit 7a52a9cfc8
2 changed files with 28 additions and 15 deletions
+26 -15
View File
@@ -3,14 +3,14 @@ package cli_test
import (
"bytes"
"context"
"io"
"crypto/sha256"
"encoding/hex"
"os"
"path/filepath"
"testing"
"github.com/codeclysm/extract"
"github.com/google/uuid"
"github.com/ory/dockertest/v3/docker/pkg/archive"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/clitest"
@@ -20,6 +20,26 @@ import (
"github.com/coder/coder/pty/ptytest"
)
// dirSum calculates a checksum of the files in a directory.
func dirSum(t *testing.T, dir string) string {
ents, err := os.ReadDir(dir)
require.NoError(t, err)
sum := sha256.New()
for _, e := range ents {
path := filepath.Join(dir, e.Name())
stat, err := os.Stat(path)
require.NoError(t, err)
byt, err := os.ReadFile(
path,
)
require.NoError(t, err, "mode: %+v", stat.Mode())
_, _ = sum.Write(byt)
}
return hex.EncodeToString(sum.Sum(nil))
}
func TestTemplatePull(t *testing.T) {
t.Parallel()
@@ -73,7 +93,6 @@ func TestTemplatePull(t *testing.T) {
// and writes it to the correct directory.
t.Run("ToDir", func(t *testing.T) {
t.Parallel()
t.Skip("FLAKE: @ammario to fix imminently")
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
@@ -120,18 +139,10 @@ func TestTemplatePull(t *testing.T) {
require.NoError(t, <-errChan)
expectedTarRd, err := archive.Tar(expectedDest, archive.Uncompressed)
require.NoError(t, err)
expectedTar, err := io.ReadAll(expectedTarRd)
require.NoError(t, err)
actualTarRd, err := archive.Tar(actualDest, archive.Uncompressed)
require.NoError(t, err)
actualTar, err := io.ReadAll(actualTarRd)
require.NoError(t, err)
require.True(t, bytes.Equal(expectedTar, actualTar), "tar files differ")
require.Equal(t,
dirSum(t, expectedDest),
dirSum(t, actualDest),
)
})
// FolderConflict tests that 'templates pull' fails when a folder with has
+2
View File
@@ -225,6 +225,7 @@ func Tar(responses *Responses) ([]byte, error) {
err = writer.WriteHeader(&tar.Header{
Name: fmt.Sprintf("%d.provision.apply.protobuf", index),
Size: int64(len(data)),
Mode: 0o644,
})
if err != nil {
return nil, err
@@ -242,6 +243,7 @@ func Tar(responses *Responses) ([]byte, error) {
err = writer.WriteHeader(&tar.Header{
Name: fmt.Sprintf("%d.provision.plan.protobuf", index),
Size: int64(len(data)),
Mode: 0o644,
})
if err != nil {
return nil, err