From 2be6023c1ace26be3dc87b706ca25ed44ce53842 Mon Sep 17 00:00:00 2001 From: James Tucker <raggi@google.com> Date: Thu, 25 Apr 2019 17:45:39 -0700 Subject: [PATCH] [pm publish] add test coverage for -lp Change-Id: I6bcdf169f8db3246911a47726373fc7190dc46a8 --- .../go/src/pm/cmd/pm/publish/publish_test.go | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/garnet/go/src/pm/cmd/pm/publish/publish_test.go b/garnet/go/src/pm/cmd/pm/publish/publish_test.go index 4061b86ee02..c88a8d30538 100644 --- a/garnet/go/src/pm/cmd/pm/publish/publish_test.go +++ b/garnet/go/src/pm/cmd/pm/publish/publish_test.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "os" "path/filepath" + "sort" "strconv" "testing" @@ -66,6 +67,65 @@ func TestPublishArchive(t *testing.T) { } } +func TestPublishListOfPackages(t *testing.T) { + build.BuildTestPackage(cfg) + + depfilePath := filepath.Join(cfg.OutputDir, "depfile.d") + + outputManifestPath := filepath.Join(cfg.OutputDir, "package_manifest.json") + packagesListPath := filepath.Join(cfg.OutputDir, "packages.list") + + if err := ioutil.WriteFile(packagesListPath, []byte(outputManifestPath+"\n"), os.ModePerm); err != nil { + t.Fatal(err) + } + + repoDir, err := ioutil.TempDir("", "pm-publish-test-repo") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(repoDir) + + if err := Run(cfg, []string{"-repo", repoDir, "-depfile", depfilePath, "-lp", "-f", packagesListPath}); err != nil { + t.Fatal(err) + } + + assertHasTestPackage(t, repoDir) + + outName, inputPaths := readDepfile(depfilePath) + if ex := filepath.Join(repoDir, "repository", "timestamp.json"); ex != outName { + t.Errorf("depfile output: got %q, want %q", outName, ex) + } + + if inputPaths[0] != packagesListPath { + t.Errorf("depfile inputs: %q != %q", inputPaths[0], packagesListPath) + } + if inputPaths[1] != outputManifestPath { + t.Errorf("depfile inputs: %q != %q", inputPaths[1], outputManifestPath) + } + + inputPaths = inputPaths[2:] + sort.Strings(inputPaths) + + blobs, err := cfg.BlobInfo() + if err != nil { + t.Fatal(err) + } + if len(inputPaths) != len(blobs) { + t.Errorf("deps entries: %#v != %#v", inputPaths, blobs) + } + sourcePaths := []string{} + for _, blob := range blobs { + sourcePaths = append(sourcePaths, blob.SourcePath) + } + sort.Strings(sourcePaths) + + for i := range sourcePaths { + if inputPaths[i] != sourcePaths[i] { + t.Errorf("deps entry: %q != %q", inputPaths[i], sourcePaths[i]) + } + } +} + func readDepfile(depfilePath string) (string, []string) { b, err := ioutil.ReadFile(depfilePath) if err != nil { -- GitLab