Manager: add Shaman checkout test

This commit is contained in:
Sybren A. Stüvel 2022-03-25 12:35:33 +01:00
parent d0139e8270
commit ccf45f2f6c
2 changed files with 53 additions and 49 deletions

View File

@ -1,9 +1,62 @@
package checkout package checkout
import ( import (
"context"
"os"
"path"
"testing" "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) { func Test_isValidCheckoutPath(t *testing.T) {
tests := []struct { tests := []struct {
name string name string

View File

@ -54,52 +54,3 @@ func TestReportRequirements(t *testing.T) {
{Sha: spec3.Sha, Size: spec3.Size, Path: spec3.Path, Status: api.ShamanFileStatusUnknown}, {Sha: spec3.Sha, Size: spec3.Size, Path: spec3.Path, Status: api.ShamanFileStatusUnknown},
}, response.Files) }, 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)
// }