package dir_test

import (
	"os"
	"path"
	"testing"

	"github.com/mlafeldt/chef-runner/resolver/dir"
	"github.com/mlafeldt/chef-runner/util"
	"github.com/stretchr/testify/assert"
)

const CookbookPath = "test-cookbooks"

func TestResolve(t *testing.T) {
	if err := os.Chdir("../../testdata"); err != nil {
		panic(err)
	}

	defer os.RemoveAll(CookbookPath)

	assert.NoError(t, dir.Resolver{}.Resolve(CookbookPath))

	expectFiles := []string{
		"practicingruby/README.md",
		"practicingruby/attributes",
		"practicingruby/metadata.rb",
		"practicingruby/recipes",
	}
	for _, f := range expectFiles {
		assert.True(t, util.FileExist(path.Join(CookbookPath, f)))
	}
}

package dir_test

import (
	"os"
	"path"
	"testing"

	"github.com/mlafeldt/chef-runner/resolver/dir"
	"github.com/mlafeldt/chef-runner/util"
	"github.com/stretchr/testify/assert"
)

func TestResolve(t *testing.T) {
	util.InDir("../../testdata", func() {
		cookbookPath := "test-cookbooks"
		defer os.RemoveAll(cookbookPath)

		assert.NoError(t, dir.Resolver{}.Resolve(cookbookPath))

		expectFiles := []string{
			"practicingruby/README.md",
			"practicingruby/attributes",
			"practicingruby/metadata.rb",
			"practicingruby/recipes",
		}
		for _, f := range expectFiles {
			assert.True(t, util.FileExist(path.Join(cookbookPath, f)))
		}
	})
}

Fix Dir resolver test to succeed with multiple CPUs
Fix Dir resolver test to succeed with multiple CPUs

Fixes this problem:

  $ go test -cpu=1,2 ./...
  ...
  --- FAIL: TestResolve (0.00 seconds)
  panic: chdir ../../testdata: no such file or directory [recovered]

See https://blog.splice.com/lesser-known-features-go-test/
