| 1 | /* |
| 2 | Copyright 2020 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package tarscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/ |
| 18 | |
| 19 | import ( |
| 20 | "archive/tarscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/" |
| 21 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 22 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 23 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 24 | "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 25 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 26 | |
| 27 | "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/" |
| 28 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/" |
| 29 | ) |
| 30 | |
| 31 | func TestCompressscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/TestCompress().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 32 | baseTmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().() |
| 33 | |
| 34 | for _, fileName := range []string{ |
| 35 | "1.txt", "2.bin", "3.md", |
| 36 | } { |
| 37 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.0 os/WriteFile().( |
| 38 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, fileName), |
| 39 | []byte{1, 2, 3}, |
| 40 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileModescip-go gomod github.com/golang/go/src go1.24.0 os/FileMode#(0o644), |
| 41 | )) |
| 42 | } |
| 43 | |
| 44 | subTmpDir := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, "sub") |
| 45 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.24.0 os/MkdirAll().(subTmpDir, osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileModescip-go gomod github.com/golang/go/src go1.24.0 os/FileMode#(0o755))) |
| 46 | |
| 47 | for _, fileName := range []string{ |
| 48 | "4.txt", "5.bin", "6.md", |
| 49 | } { |
| 50 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.0 os/WriteFile().( |
| 51 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(subTmpDir, fileName), |
| 52 | []byte{4, 5, 6}, |
| 53 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileModescip-go gomod github.com/golang/go/src go1.24.0 os/FileMode#(0o644), |
| 54 | )) |
| 55 | } |
| 56 | |
| 57 | logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/.SetLevelscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/SetLevel().(logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/.DebugLevelscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/DebugLevel.) |
| 58 | |
| 59 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.Symlinkscip-go gomod github.com/golang/go/src go1.24.0 os/Symlink().( |
| 60 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, "1.txt"), |
| 61 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(subTmpDir, "link"), |
| 62 | )) |
| 63 | |
| 64 | excludes := []*regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#{ |
| 65 | regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(".md"), |
| 66 | regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().("5"), |
| 67 | } |
| 68 | |
| 69 | tarFilePath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, "res.tar.gz") |
| 70 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, Compressscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/Compress().(tarFilePath, baseTmpDir, excludes...)) |
| 71 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.FileExistsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/FileExists().(t, tarFilePath) |
| 72 | |
| 73 | res := []string{"1.txt", "2.bin", "sub/4.txt", "sub/link"} |
| 74 | |
| 75 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, iterateTarballscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/iterateTarball().( |
| 76 | tarFilePath, func(_ *tarscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/.Readerscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/Reader#, header *tarscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/.Headerscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/Header#) (bool, error) { |
| 77 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, res[0], header.Namescip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/Header#Name.) |
| 78 | res = res[1:] |
| 79 | |
| 80 | return false, nil |
| 81 | }), |
| 82 | ) |
| 83 | } |
| 84 | |
| 85 | func TestCompressWithoutPreservingPathscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/TestCompressWithoutPreservingPath().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 86 | baseTmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().() |
| 87 | compressDir := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, "to_compress") |
| 88 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.24.0 os/MkdirAll().(compressDir, osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileModescip-go gomod github.com/golang/go/src go1.24.0 os/FileMode#(0o755))) |
| 89 | |
| 90 | for _, fileName := range []string{ |
| 91 | "1.txt", "2.bin", "3.md", |
| 92 | } { |
| 93 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.0 os/WriteFile().( |
| 94 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(compressDir, fileName), |
| 95 | []byte{1, 2, 3}, |
| 96 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileModescip-go gomod github.com/golang/go/src go1.24.0 os/FileMode#(0o644), |
| 97 | )) |
| 98 | } |
| 99 | |
| 100 | logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/.SetLevelscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/SetLevel().(logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/.DebugLevelscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/DebugLevel.) |
| 101 | |
| 102 | tarFilePath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, "res.tar.gz") |
| 103 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, CompressWithoutPreservingPathscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/CompressWithoutPreservingPath().(tarFilePath, compressDir)) |
| 104 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.FileExistsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/FileExists().(t, tarFilePath) |
| 105 | |
| 106 | res := []string{"1.txt", "2.bin", "3.md"} |
| 107 | |
| 108 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, iterateTarballscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/iterateTarball().( |
| 109 | tarFilePath, func(_ *tarscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/.Readerscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/Reader#, header *tarscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/.Headerscip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/Header#) (bool, error) { |
| 110 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, res[0], header.Namescip-go gomod github.com/golang/go/src go1.24.0 `archive/tar`/Header#Name.) |
| 111 | res = res[1:] |
| 112 | |
| 113 | return false, nil |
| 114 | }), |
| 115 | ) |
| 116 | } |
| 117 | |
| 118 | func TestExtractscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/TestExtract().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 119 | tarball := []byte{ |
| 120 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xec, 0xd7, |
| 121 | 0xdf, 0xea, 0x82, 0x30, 0x14, 0xc0, 0xf1, 0xfd, 0xfe, 0xd4, 0x73, 0xf4, |
| 122 | 0x02, 0xb9, 0xb3, 0x9d, 0xb9, 0xd9, 0xe3, 0xa8, 0x08, 0x49, 0x69, 0xe2, |
| 123 | 0x26, 0xf4, 0xf8, 0x31, 0x93, 0x2e, 0xba, 0x10, 0x8a, 0xe6, 0x08, 0xcf, |
| 124 | 0xe7, 0x66, 0x0c, 0xc4, 0x1d, 0x2f, 0xbe, 0x30, 0x45, 0xe2, 0xae, 0x8e, |
| 125 | 0x85, 0x05, 0x00, 0xa0, 0x95, 0xf2, 0xab, 0x30, 0x29, 0x8c, 0x7b, 0x71, |
| 126 | 0xdf, 0x4f, 0x90, 0x09, 0x34, 0x29, 0x00, 0x48, 0xd4, 0x9a, 0x81, 0x90, |
| 127 | 0x0a, 0x91, 0xed, 0x20, 0xf0, 0x5c, 0xa3, 0xc1, 0xba, 0xbc, 0x67, 0x00, |
| 128 | 0x36, 0xb7, 0xe5, 0x31, 0x9f, 0x7b, 0xae, 0xea, 0xed, 0xcc, 0x7b, 0xa6, |
| 129 | 0x2f, 0x79, 0xac, 0x5f, 0xe2, 0xe7, 0xf7, 0x2f, 0xf6, 0x08, 0x24, 0x22, |
| 130 | 0x99, 0x14, 0x75, 0x1b, 0xf8, 0x8c, 0x37, 0xfa, 0x47, 0x9d, 0x52, 0xff, |
| 131 | 0x4b, 0xa0, 0xfe, 0xd7, 0xcd, 0x0e, 0x05, 0x57, 0x81, 0xef, 0x00, 0xaf, |
| 132 | 0xf7, 0x8f, 0x52, 0x1a, 0xea, 0x7f, 0x09, 0xff, 0x9b, 0x6d, 0xec, 0x11, |
| 133 | 0x48, 0x44, 0xbe, 0xff, 0x73, 0xdd, 0x9e, 0x42, 0x9e, 0xe1, 0x7b, 0x30, |
| 134 | 0xc6, 0xcc, 0xf4, 0x0f, 0x4f, 0xfd, 0x1b, 0xed, 0xef, 0xff, 0x92, 0xbb, |
| 135 | 0xa6, 0xe3, 0xe5, 0xa5, 0xe9, 0xfa, 0xca, 0xda, 0xfd, 0x01, 0x33, 0x25, |
| 136 | 0x54, 0x86, 0x8a, 0x7f, 0xf2, 0xa7, 0x65, 0xe5, 0xfd, 0x13, 0x42, 0xd6, |
| 137 | 0xeb, 0x16, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xde, 0xbe, 0xdf, 0x00, 0x12, |
| 138 | 0x00, 0x00, |
| 139 | } |
| 140 | file, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.CreateTempscip-go gomod github.com/golang/go/src go1.24.0 os/CreateTemp().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), "tarball") |
| 141 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 142 | |
| 143 | defer osscip-go gomod github.com/golang/go/src go1.24.0 os/.Removescip-go gomod github.com/golang/go/src go1.24.0 os/Remove().(file.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().()) |
| 144 | |
| 145 | _, err = file.Writescip-go gomod github.com/golang/go/src go1.24.0 os/File#Write().(tarball) |
| 146 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 147 | |
| 148 | baseTmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().() |
| 149 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, Extractscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/Extract().(file.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().(), baseTmpDir)) |
| 150 | res := []string{ |
| 151 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(baseTmpDir), |
| 152 | "1.txt", |
| 153 | "2.bin", |
| 154 | "sub", |
| 155 | "4.txt", |
| 156 | "link", |
| 157 | } |
| 158 | |
| 159 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Walkscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Walk().( |
| 160 | baseTmpDir, |
| 161 | func(_ string, fileInfo osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.24.0 os/FileInfo#, _ error) error { |
| 162 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, res[0], fileInfo.Namescip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#Name().()) |
| 163 | |
| 164 | if res[0] == "link" { |
| 165 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.ModeSymlinkscip-go gomod github.com/golang/go/src go1.24.0 os/ModeSymlink., fileInfo.Modescip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#Mode().()&osscip-go gomod github.com/golang/go/src go1.24.0 os/.ModeSymlinkscip-go gomod github.com/golang/go/src go1.24.0 os/ModeSymlink.) |
| 166 | } |
| 167 | |
| 168 | res = res[1:] |
| 169 | |
| 170 | return nil |
| 171 | }, |
| 172 | )) |
| 173 | } |
| 174 | |
| 175 | func TestReadFileFromGzippedTarscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/TestReadFileFromGzippedTar().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 176 | baseTmpDir := t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().() |
| 177 | |
| 178 | const ( |
| 179 | testFilePath = "test.txt" |
| 180 | testFileContents = "test-file-contents" |
| 181 | ) |
| 182 | |
| 183 | testTarPath := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, "test.tar.gz") |
| 184 | |
| 185 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, osscip-go gomod github.com/golang/go/src go1.24.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.0 os/WriteFile().( |
| 186 | filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().(baseTmpDir, testFilePath), |
| 187 | []byte(testFileContents), |
| 188 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.FileModescip-go gomod github.com/golang/go/src go1.24.0 os/FileMode#(0o644), |
| 189 | )) |
| 190 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, Compressscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/Compress().(testTarPath, baseTmpDir, nil)) |
| 191 | |
| 192 | type args struct { |
| 193 | tarPath string |
| 194 | filePath string |
| 195 | } |
| 196 | |
| 197 | type want struct { |
| 198 | fileContents string |
| 199 | shouldErr bool |
| 200 | } |
| 201 | |
| 202 | cases := map[string]struct { |
| 203 | args args |
| 204 | want want |
| 205 | }{ |
| 206 | "FoundFileInTar": { |
| 207 | args: args{ |
| 208 | tarPath: testTarPath, |
| 209 | filePath: testFilePath, |
| 210 | }, |
| 211 | want: want{fileContents: testFileContents}, |
| 212 | }, |
| 213 | "FileNotInTar": { |
| 214 | args: args{ |
| 215 | tarPath: testTarPath, |
| 216 | filePath: "badfile.txt", |
| 217 | }, |
| 218 | want: want{shouldErr: true}, |
| 219 | }, |
| 220 | } |
| 221 | |
| 222 | for name, tc := range cases { |
| 223 | t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(name, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 224 | r, err := ReadFileFromGzippedTarscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/tar`/ReadFileFromGzippedTar().(tc.args.tarPath, tc.args.filePath) |
| 225 | if tc.want.shouldErr { |
| 226 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Nil().(t, r) |
| 227 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 228 | } else { |
| 229 | file, err := ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(r) |
| 230 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 231 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, tc.want.fileContents, string(file)) |
| 232 | } |
| 233 | }) |
| 234 | } |
| 235 | } |