Skip to content

fix: flake in template pull #6317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions cli/templatepull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions provisioner/echo/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down