MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / TestPackageVersions

Function TestPackageVersions

pkg/cmd/package/versions/versions_test.go:21–202  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19var rootResource = testutil.NewRootResource()
20
21func TestPackageVersions(t *testing.T) {
22 const spaceID = "Spaces-1"
23 space1 := fixtures.NewSpace(spaceID, "Default Space")
24
25 builtInFeed, _ := feeds.NewBuiltInFeed("builtin")
26 builtInFeed.ID = "Feeds-109"
27
28 refTime := time.Date(2022, 9, 29, 11, 26, 0, 0, time.UTC)
29
30 tests := []struct {
31 name string
32 run func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer)
33 }{
34 {"package versions requires a package ID", func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) {
35 cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) {
36 defer api.Close()
37 rootCmd.SetArgs([]string{"package", "versions"})
38 return rootCmd.ExecuteC()
39 })
40
41 _, err := testutil.ReceivePair(cmdReceiver)
42 assert.EqualError(t, err, "package must be specified")
43
44 assert.Equal(t, "", stdOut.String())
45 assert.Equal(t, "", stdErr.String())
46 }},
47
48 {name: "lists all package versions", run: func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) {
49 cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) {
50 defer api.Close()
51 rootCmd.SetArgs([]string{"package", "versions", "--package", "pterm"})
52 return rootCmd.ExecuteC()
53 })
54
55 api.ExpectRequest(t, "GET", "/api/").RespondWith(rootResource)
56 api.ExpectRequest(t, "GET", "/api/Spaces-1").RespondWith(rootResource)
57
58 api.ExpectRequest(t, "GET", "/api/Spaces-1/feeds?feedType=BuiltIn&take=1").RespondWith(&resources.Resources[feeds.IFeed]{
59 Items: []feeds.IFeed{
60 builtInFeed,
61 },
62 })
63 api.ExpectRequest(t, "GET", "/api/Spaces-1/feeds/Feeds-109/packages/versions?packageId=pterm&take=2147483647").RespondWith(&resources.Resources[*packages.PackageVersion]{
64 Items: []*packages.PackageVersion{
65 {Version: "1.1", SizeBytes: 67890, Published: refTime.Add(5 * time.Hour)},
66 {Version: "1.0.7", SizeBytes: 55231, Published: refTime.Add(2 * time.Hour)},
67 {Version: "0.99-beta", SizeBytes: 53001, Published: refTime},
68 },
69 })
70
71 _, err := testutil.ReceivePair(cmdReceiver)
72 assert.Nil(t, err)
73 // Note these tests print times in UTC all the time because our refTime is UTC. The server specifies DateTimeOffset, we believe go will
74 // automagically convert these to local time and print them nicely in the real world
75 assert.Equal(t, heredoc.Doc(`
76 VERSION PUBLISHED SIZE
77 1.1 2022-09-29 16:26:00 66.3 KiB
78 1.0.7 2022-09-29 13:26:00 53.9 KiB

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
ExpectRequestMethod · 0.95
NewSpaceFunction · 0.92
GoBegin2Function · 0.92
ReceivePairFunction · 0.92
NewMockHttpServerFunction · 0.92
RespondWithMethod · 0.80

Tested by

no test coverage detected