1package cmd_test 2 3import ( 4 "errors" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 9 . "github.com/cloudfoundry/bosh-cli/cmd" 10 boshreldir "github.com/cloudfoundry/bosh-cli/releasedir" 11 fakereldir "github.com/cloudfoundry/bosh-cli/releasedir/releasedirfakes" 12 fakeui "github.com/cloudfoundry/bosh-cli/ui/fakes" 13 boshtbl "github.com/cloudfoundry/bosh-cli/ui/table" 14) 15 16var _ = Describe("BlobsCmd", func() { 17 var ( 18 blobsDir *fakereldir.FakeBlobsDir 19 ui *fakeui.FakeUI 20 command BlobsCmd 21 ) 22 23 BeforeEach(func() { 24 blobsDir = &fakereldir.FakeBlobsDir{} 25 ui = &fakeui.FakeUI{} 26 command = NewBlobsCmd(blobsDir, ui) 27 }) 28 29 Describe("Run", func() { 30 act := func() error { return command.Run() } 31 32 It("lists blobs", func() { 33 blobs := []boshreldir.Blob{ 34 boshreldir.Blob{ 35 Path: "fake-path", 36 Size: 100, 37 38 BlobstoreID: "fake-blob-id", 39 SHA1: "fake-sha1", 40 }, 41 boshreldir.Blob{ 42 Path: "dir/fake-path", 43 Size: 1000, 44 45 BlobstoreID: "", 46 SHA1: "fake-sha2", 47 }, 48 } 49 50 blobsDir.BlobsReturns(blobs, nil) 51 52 err := act() 53 Expect(err).ToNot(HaveOccurred()) 54 55 Expect(ui.Table).To(Equal(boshtbl.Table{ 56 Content: "blobs", 57 58 Header: []boshtbl.Header{ 59 boshtbl.NewHeader("Path"), 60 boshtbl.NewHeader("Size"), 61 boshtbl.NewHeader("Blobstore ID"), 62 boshtbl.NewHeader("Digest"), 63 }, 64 65 SortBy: []boshtbl.ColumnSort{{Column: 0, Asc: true}}, 66 67 Rows: [][]boshtbl.Value{ 68 { 69 boshtbl.NewValueString("fake-path"), 70 boshtbl.NewValueBytes(100), 71 boshtbl.NewValueString("fake-blob-id"), 72 boshtbl.NewValueString("fake-sha1"), 73 }, 74 { 75 boshtbl.NewValueString("dir/fake-path"), 76 boshtbl.NewValueBytes(1000), 77 boshtbl.NewValueString("(local)"), 78 boshtbl.NewValueString("fake-sha2"), 79 }, 80 }, 81 })) 82 }) 83 84 It("returns error if blobs cannot be retrieved", func() { 85 blobsDir.BlobsReturns(nil, errors.New("fake-err")) 86 87 err := act() 88 Expect(err).To(HaveOccurred()) 89 Expect(err.Error()).To(ContainSubstring("fake-err")) 90 }) 91 }) 92}) 93