tests: Correct basis dir setup

I noticed we were still catching the default locations for dirs in test
and just appending a tempdir path inside of them. This fixes that and
ensures all test files are contained within the tmpdir.
This commit is contained in:
Paul Hinze 2022-05-18 17:03:10 -05:00
parent 625806f448
commit 5bd0ac371c
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -4,6 +4,7 @@ import (
"context"
"io/ioutil"
"os"
"path/filepath"
"github.com/hashicorp/vagrant-plugin-sdk/core"
coremocks "github.com/hashicorp/vagrant-plugin-sdk/core/mocks"
@ -79,8 +80,20 @@ func TestBasis(t testing.T, opts ...BasisOption) (b *Basis) {
require.NoError(t, err)
t.Cleanup(func() { os.RemoveAll(td) })
projDir, err := datadir.NewBasis(td)
require.NoError(t, err)
mkSubdir := func(root, sub string) string {
sd := filepath.Join(root, sub)
require.NoError(t, os.Mkdir(sd, 0755))
return sd
}
projDir := &datadir.Basis{
Dir: datadir.NewBasicDir(
mkSubdir(td, "config"),
mkSubdir(td, "cache"),
mkSubdir(td, "data"),
mkSubdir(td, "temp"),
),
}
defaultOpts := []BasisOption{
WithClient(singleprocess.TestServer(t)),