|
| 1 | +package cmd_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/jedib0t/go-pretty/v6/table" |
| 7 | + . "github.com/onsi/ginkgo/v2" |
| 8 | + //. "github.com/onsi/gomega" |
| 9 | + "github.com/stretchr/testify/mock" |
| 10 | + |
| 11 | + "github.com/codesphere-cloud/oms/cli/cmd" |
| 12 | + "github.com/codesphere-cloud/oms/internal/portal" |
| 13 | + "github.com/codesphere-cloud/oms/internal/util" |
| 14 | +) |
| 15 | + |
| 16 | +var _ = Describe("ListPackages", func() { |
| 17 | + |
| 18 | + var ( |
| 19 | + mockTableWriter util.MockTableWriter |
| 20 | + c cmd.ListBuildsCmd |
| 21 | + internal bool |
| 22 | + buildDate time.Time |
| 23 | + ) |
| 24 | + BeforeEach(func() { |
| 25 | + c = cmd.ListBuildsCmd{ |
| 26 | + Opts: cmd.ListBuildsOpts{ |
| 27 | + Internal: internal, |
| 28 | + }, |
| 29 | + TableWriter: &mockTableWriter, |
| 30 | + } |
| 31 | + |
| 32 | + buildDate, _ = time.Parse("2006-01-02", "2025-05-01") |
| 33 | + |
| 34 | + // header is always appended |
| 35 | + mockTableWriter.EXPECT().AppendHeader(mock.Anything) |
| 36 | + mockTableWriter.EXPECT().Render().Return("") |
| 37 | + }) |
| 38 | + |
| 39 | + Context("Internal packages are excluded", func() { |
| 40 | + It("doesn't list internal packages, artifacts are separated by ,", func() { |
| 41 | + mockTableWriter.EXPECT().AppendRow( |
| 42 | + table.Row{"", "1.42", buildDate, "externalBuild", "installer.tar, installer2.tar"}, |
| 43 | + ) |
| 44 | + c.PrintPackagesTable( |
| 45 | + portal.CodesphereBuilds{ |
| 46 | + Builds: []portal.CodesphereBuild{ |
| 47 | + { |
| 48 | + Hash: "externalBuild", |
| 49 | + Version: "1.42", |
| 50 | + Date: buildDate, |
| 51 | + Internal: false, |
| 52 | + Artifacts: []portal.Artifact{ |
| 53 | + {Filename: "installer.tar"}, |
| 54 | + {Filename: "installer2.tar"}, |
| 55 | + }, |
| 56 | + }, |
| 57 | + { |
| 58 | + Hash: "internalBuild", |
| 59 | + Internal: true, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }) |
| 63 | + }) |
| 64 | + |
| 65 | + }) |
| 66 | + Context("Internal packages are included", func() { |
| 67 | + BeforeEach(func() { |
| 68 | + internal = true |
| 69 | + }) |
| 70 | + It("marks internal packages with a *", func() { |
| 71 | + mockTableWriter.EXPECT().AppendRow( |
| 72 | + table.Row{"", "1.42", buildDate, "externalBuild", "installer.tar, installer2.tar"}, |
| 73 | + ) |
| 74 | + mockTableWriter.EXPECT().AppendRow( |
| 75 | + table.Row{"*", "master", buildDate, "internalBuild", "installer.tar, installer2.tar"}, |
| 76 | + ) |
| 77 | + c.PrintPackagesTable( |
| 78 | + portal.CodesphereBuilds{ |
| 79 | + Builds: []portal.CodesphereBuild{ |
| 80 | + { |
| 81 | + Hash: "externalBuild", |
| 82 | + Version: "1.42", |
| 83 | + Date: buildDate, |
| 84 | + Internal: false, |
| 85 | + Artifacts: []portal.Artifact{ |
| 86 | + {Filename: "installer.tar"}, |
| 87 | + {Filename: "installer2.tar"}, |
| 88 | + }, |
| 89 | + }, |
| 90 | + { |
| 91 | + Hash: "internalBuild", |
| 92 | + Version: "master", |
| 93 | + Date: buildDate, |
| 94 | + Internal: true, |
| 95 | + Artifacts: []portal.Artifact{ |
| 96 | + {Filename: "installer.tar"}, |
| 97 | + {Filename: "installer2.tar"}, |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }) |
| 102 | + }) |
| 103 | + }) |
| 104 | +}) |
0 commit comments