From b4587fe791febac1068372959185d67b14979db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20=C4=B0kinci?= Date: Sat, 7 May 2022 18:49:44 +0300 Subject: [PATCH] fix #4 CopyToContainer appender tests completed --- README.md | 2 +- pkg/container_manager/container_manager.go | 4 ++ .../container_manager_test.go | 44 +++++++++++++++++++ testdata/.test_point_folder/testfile | 0 testdata/node_modules/testfile | 0 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 testdata/.test_point_folder/testfile create mode 100644 testdata/node_modules/testfile diff --git a/README.md b/README.md index 0615a7e..05a81d1 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ go test ./... - Add timestamp to container names ✅[Issue#2](https://github.com/muhammedikinci/pin/issues/2) - Create small pieces with extracting codes from runner struct and write unit test: - Image Manager ✅[Issue#3](https://github.com/muhammedikinci/pin/issues/3) - - Container Manager Not Completed Yet [Issue#4](https://github.com/muhammedikinci/pin/issues/4) + - Container Manager ✅[Issue#4](https://github.com/muhammedikinci/pin/issues/4) - Shell Commander ✅[Issue#5](https://github.com/muhammedikinci/pin/issues/5) - Parser - Runner diff --git a/pkg/container_manager/container_manager.go b/pkg/container_manager/container_manager.go index 4a0ca12..9a62984 100644 --- a/pkg/container_manager/container_manager.go +++ b/pkg/container_manager/container_manager.go @@ -124,6 +124,10 @@ func (cm containerManager) appender(path string, info os.FileInfo, err error, cu return nil } + if strings.Contains(header.Name, "node_modules") { + return nil + } + if err := tw.WriteHeader(header); err != nil { return err } diff --git a/pkg/container_manager/container_manager_test.go b/pkg/container_manager/container_manager_test.go index a39f102..7d6bd37 100644 --- a/pkg/container_manager/container_manager_test.go +++ b/pkg/container_manager/container_manager_test.go @@ -1,8 +1,16 @@ package container_manager import ( + "archive/tar" + "bytes" "context" "errors" + "fmt" + "io" + "os" + "path" + "path/filepath" + "strings" "testing" "github.com/docker/docker/api/types/container" @@ -198,3 +206,39 @@ func TestWhenContainerRemoveReturnNilRemoveContainerMustReturnNil(t *testing.T) assert.Equal(t, err, nil) } + +func TestAppender(t *testing.T) { + var buf bytes.Buffer + + tw := tar.NewWriter(&buf) + basepath, _ := os.Getwd() + dir := filepath.Dir(filepath.Dir(basepath)) + currentPath := filepath.FromSlash(path.Join(dir, "testdata")) + fmt.Println(dir) + cm := containerManager{} + + err := filepath.Walk(currentPath, func(path string, info os.FileInfo, err error) error { + return cm.appender(path, info, err, currentPath, tw) + }) + + assert.Equal(t, err, nil) + + tw.Close() + + tr := tar.NewReader(&buf) + + for { + header, err := tr.Next() + if err != nil { + if err == io.EOF { + break + } + } + if header == nil { + break + } + + assert.Equal(t, header.Name[0] == '.', false) + assert.Equal(t, strings.Contains(header.Name, "node_modules"), false) + } +} diff --git a/testdata/.test_point_folder/testfile b/testdata/.test_point_folder/testfile new file mode 100644 index 0000000..e69de29 diff --git a/testdata/node_modules/testfile b/testdata/node_modules/testfile new file mode 100644 index 0000000..e69de29