Remember: These are wiremock-style tests which simulate the HTTP requests and responses from Octopus Server. That layer is handled by the go-octopusdeploy library which has its own integration tests that upload packages, both delta and not, to a real Octopus Server. This test suite is about the CLI'
(t *testing.T)
| 30 | // That layer is handled by the go-octopusdeploy library which has its own integration tests that upload packages, |
| 31 | // both delta and not, to a real Octopus Server. This test suite is about the CLI's interaction with the library. |
| 32 | func TestPackageUpload(t *testing.T) { |
| 33 | const spaceID = "Spaces-1" |
| 34 | space1 := fixtures.NewSpace(spaceID, "Default Space") |
| 35 | |
| 36 | // we need a bigger file to make the delta worthwhile. Random so it shouldn't compress too much |
| 37 | randomContent1 := make([]byte, 2*1024) |
| 38 | _, err := cryptoRand.Read(randomContent1) |
| 39 | require.NoError(t, err) |
| 40 | |
| 41 | zipFileBytes1 := createZip(t, zippedFile{ |
| 42 | name: "content.txt", |
| 43 | content: randomContent1, |
| 44 | }) |
| 45 | |
| 46 | randomContent2 := make([]byte, 2*1024) |
| 47 | _, err = cryptoRand.Read(randomContent2) |
| 48 | require.NoError(t, err) |
| 49 | |
| 50 | zipFileBytes2 := createZip(t, zippedFile{ |
| 51 | name: "content.txt", |
| 52 | content: randomContent1, |
| 53 | }, zippedFile{ |
| 54 | name: "content2.txt", |
| 55 | content: randomContent2, |
| 56 | }) |
| 57 | |
| 58 | const testPkg1FileName = "test.1.0.zip" |
| 59 | const otherPkg11FileName = "other.1.1.zip" |
| 60 | const deltaPkg1FileName = "deltapkg.1.0.zip" |
| 61 | const deltaPkg2FileName = "deltapkg.2.0.zip" |
| 62 | |
| 63 | // this is our "virtual filesystem". It's not really a VFS and we can't unit test path globbing at the moment, but it'll do |
| 64 | files := map[string][]byte{ |
| 65 | testPkg1FileName: []byte("test1-contents"), |
| 66 | otherPkg11FileName: []byte("other-contents"), |
| 67 | // for delta upload tests |
| 68 | deltaPkg1FileName: zipFileBytes1, |
| 69 | deltaPkg2FileName: zipFileBytes2, |
| 70 | } |
| 71 | opener := func(name string) (io.ReadSeekCloser, error) { |
| 72 | if contents, ok := files[name]; ok { |
| 73 | return &nopReadSeekCloser{inner: bytes.NewReader(contents)}, nil |
| 74 | } else { |
| 75 | return nil, os.ErrNotExist |
| 76 | } |
| 77 | } |
| 78 | contextWithOpener := context.WithValue(context.TODO(), constants.ContextKeyOsOpen, opener) |
| 79 | |
| 80 | tests := []struct { |
| 81 | name string |
| 82 | run func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) |
| 83 | }{ |
| 84 | {"requires at least one package", func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) { |
| 85 | cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) { |
| 86 | defer api.Close() |
| 87 | rootCmd.SetArgs([]string{"package", "upload"}) |
| 88 | return rootCmd.ExecuteC() |
| 89 | }) |
nothing calls this directly
no test coverage detected