From ccf45f2f6ccfb61fb639b6569d419c6266cac144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 25 Mar 2022 12:35:33 +0100 Subject: [PATCH] Manager: add Shaman checkout test --- pkg/shaman/checkout/checkout_test.go | 53 +++++++++++++++++++ ...es_test.go => report_requirements_test.go} | 49 ----------------- 2 files changed, 53 insertions(+), 49 deletions(-) rename pkg/shaman/checkout/{routes_test.go => report_requirements_test.go} (54%) diff --git a/pkg/shaman/checkout/checkout_test.go b/pkg/shaman/checkout/checkout_test.go index e8884560..c64c4bed 100644 --- a/pkg/shaman/checkout/checkout_test.go +++ b/pkg/shaman/checkout/checkout_test.go @@ -1,9 +1,62 @@ package checkout import ( + "context" + "os" + "path" "testing" + + "git.blender.org/flamenco/pkg/api" + "git.blender.org/flamenco/pkg/shaman/filestore" + "github.com/stretchr/testify/assert" ) +func TestCheckout(t *testing.T) { + manager, cleanup := createTestManager() + defer cleanup() + ctx := context.Background() + + filestore.LinkTestFileStore(manager.fileStore.BasePath()) + + checkout := api.ShamanCheckout{ + CheckoutPath: "á hausinn á þér", + Files: []api.ShamanFileSpec{ + {Sha: "590c148428d5c35fab3ebad2f3365bb469ab9c531b60831f3e826c472027a0b9", Size: 3367, Path: "subdir/replacer.py"}, + {Sha: "80b749c27b2fef7255e7e7b3c2029b03b31299c75ff1f1c72732081c70a713a3", Size: 7488, Path: "feed.py"}, + {Sha: "914853599dd2c351ab7b82b219aae6e527e51518a667f0ff32244b0c94c75688", Size: 486, Path: "httpstuff.py"}, + {Sha: "d6fc7289b5196cc96748ea72f882a22c39b8833b457fe854ef4c03a01f5db0d3", Size: 7217, Path: "filesystemstuff.py"}, + }, + } + + err := manager.Checkout(ctx, checkout) + if err != nil { + t.Fatalf("fatal error: %v", err) + } + + // Check the symlinks of the checkout + coPath := path.Join(manager.checkoutBasePath, checkout.CheckoutPath) + assert.FileExists(t, path.Join(coPath, "subdir", "replacer.py")) + assert.FileExists(t, path.Join(coPath, "feed.py")) + assert.FileExists(t, path.Join(coPath, "httpstuff.py")) + assert.FileExists(t, path.Join(coPath, "filesystemstuff.py")) + + storePath := manager.fileStore.StoragePath() + assertLinksTo(t, path.Join(coPath, "subdir", "replacer.py"), + path.Join(storePath, "59", "0c148428d5c35fab3ebad2f3365bb469ab9c531b60831f3e826c472027a0b9", "3367.blob")) + assertLinksTo(t, path.Join(coPath, "feed.py"), + path.Join(storePath, "80", "b749c27b2fef7255e7e7b3c2029b03b31299c75ff1f1c72732081c70a713a3", "7488.blob")) + assertLinksTo(t, path.Join(coPath, "httpstuff.py"), + path.Join(storePath, "91", "4853599dd2c351ab7b82b219aae6e527e51518a667f0ff32244b0c94c75688", "486.blob")) + assertLinksTo(t, path.Join(coPath, "filesystemstuff.py"), + path.Join(storePath, "d6", "fc7289b5196cc96748ea72f882a22c39b8833b457fe854ef4c03a01f5db0d3", "7217.blob")) +} + +func assertLinksTo(t *testing.T, linkPath, expectedTarget string) { + actualTarget, err := os.Readlink(linkPath) + assert.Nil(t, err) + assert.Equal(t, expectedTarget, actualTarget) +} + func Test_isValidCheckoutPath(t *testing.T) { tests := []struct { name string diff --git a/pkg/shaman/checkout/routes_test.go b/pkg/shaman/checkout/report_requirements_test.go similarity index 54% rename from pkg/shaman/checkout/routes_test.go rename to pkg/shaman/checkout/report_requirements_test.go index 6ad180c1..64fc090b 100644 --- a/pkg/shaman/checkout/routes_test.go +++ b/pkg/shaman/checkout/report_requirements_test.go @@ -54,52 +54,3 @@ func TestReportRequirements(t *testing.T) { {Sha: spec3.Sha, Size: spec3.Size, Path: spec3.Path, Status: api.ShamanFileStatusUnknown}, }, response.Files) } - -// func TestCreateCheckout(t *testing.T) { -// manager, cleanup := createTestManager() -// defer cleanup() - -// filestore.LinkTestFileStore(manager.fileStore.BasePath()) - -// defFile, err := ioutil.ReadFile("../_test_file_store/checkout_definition.txt") -// assert.Nil(t, err) -// compressedDefFile := httpserver.CompressBuffer(defFile) - -// respRec := httptest.NewRecorder() -// req := httptest.NewRequest("POST", "/checkout/create/{checkoutID}", compressedDefFile) -// req = mux.SetURLVars(req, map[string]string{ -// "checkoutID": "jemoeder", -// }) -// req.Header.Set("Content-Type", "text/plain") -// req.Header.Set("Content-Encoding", "gzip") -// logrus.SetLevel(logrus.DebugLevel) -// manager.createCheckout(respRec, req) - -// bodyBytes, err := ioutil.ReadAll(respRec.Body) -// assert.Nil(t, err) -// body := string(bodyBytes) -// assert.Equal(t, http.StatusOK, respRec.Code, body) - -// // Check the symlinks of the checkout -// coPath := path.Join(manager.checkoutBasePath, "er", "jemoeder") -// assert.FileExists(t, path.Join(coPath, "subdir", "replacer.py")) -// assert.FileExists(t, path.Join(coPath, "feed.py")) -// assert.FileExists(t, path.Join(coPath, "httpstuff.py")) -// assert.FileExists(t, path.Join(coPath, "filesystemstuff.py")) - -// storePath := manager.fileStore.StoragePath() -// assertLinksTo(t, path.Join(coPath, "subdir", "replacer.py"), -// path.Join(storePath, "59", "0c148428d5c35fab3ebad2f3365bb469ab9c531b60831f3e826c472027a0b9", "3367.blob")) -// assertLinksTo(t, path.Join(coPath, "feed.py"), -// path.Join(storePath, "80", "b749c27b2fef7255e7e7b3c2029b03b31299c75ff1f1c72732081c70a713a3", "7488.blob")) -// assertLinksTo(t, path.Join(coPath, "httpstuff.py"), -// path.Join(storePath, "91", "4853599dd2c351ab7b82b219aae6e527e51518a667f0ff32244b0c94c75688", "486.blob")) -// assertLinksTo(t, path.Join(coPath, "filesystemstuff.py"), -// path.Join(storePath, "d6", "fc7289b5196cc96748ea72f882a22c39b8833b457fe854ef4c03a01f5db0d3", "7217.blob")) -// } - -// func assertLinksTo(t *testing.T, linkPath, expectedTarget string) { -// actualTarget, err := os.Readlink(linkPath) -// assert.Nil(t, err) -// assert.Equal(t, expectedTarget, actualTarget) -// }