testing/kubectl-krew: fix tests due to lingering index cache

> --- FAIL: TestKrewUpdateListsUpgradesAvailable (1.82s)
> [..]
> update_test.go:129: output should not mention update available for "ns"; output=Updated the local copy of plugin index.
> [..]
> FAIL
> FAIL	sigs.k8s.io/krew/integration_test	70.448s
This commit is contained in:
Kevin Daudt 2023-08-14 20:18:19 +00:00
parent bb1f55a885
commit dbfc838472
2 changed files with 20 additions and 1 deletions

View File

@ -8,7 +8,10 @@ arch="all !armhf !riscv64" # kubectl
license="Apache-2.0"
depends="kubectl"
makedepends="go"
source="$pkgname-$pkgver.tar.gz::https://github.com/kubernetes-sigs/krew/archive/refs/tags/v$pkgver.tar.gz"
source="
$pkgname-$pkgver.tar.gz::https://github.com/kubernetes-sigs/krew/archive/refs/tags/v$pkgver.tar.gz
test-use-testing-tmpdir.patch
"
builddir="$srcdir/krew-$pkgver"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
@ -35,4 +38,5 @@ package() {
sha512sums="
888362c564500d3f9f00b3207f5d63ee6546f9da6c884736fa55d49e78b91d5085a518f69f41b156cc8dc13667846be98bc2459392ca3d970c89721b6f4b632b kubectl-krew-0.4.4.tar.gz
797a0f1361d893289217569e09dd5564fe545eaf2f0b3dc40367c63cb124b8120c5600d190732ced7885a020ae56a9417b49bccb8bca2c87faf72bf3e1359a81 test-use-testing-tmpdir.patch
"

View File

@ -0,0 +1,15 @@
Outdated index files from previous builds break tests. Use t.TempDir() to make
sure a new index file is used.
diff --git a/integration_test/testutil_test.go b/integration_test/testutil_test.go
index 66ebc98..d91635b 100644
--- a/integration_test/testutil_test.go
+++ b/integration_test/testutil_test.go
@@ -277,7 +277,7 @@ func (it *ITest) loadReceipt(path string) index.Receipt {
// It caches the index tree as in-memory tar after the first run.
func (it *ITest) initializeIndex() {
initIndexOnce.Do(func() {
- persistentCacheFile := filepath.Join(os.TempDir(), persistentIndexCache)
+ persistentCacheFile := filepath.Join(it.t.TempDir(), persistentIndexCache)
fileInfo, err := os.Stat(persistentCacheFile)
if err == nil && fileInfo.Mode().IsRegular() {