terraform/internal/command/plugins_test.go
Sarah French 7199fbd2bb
Update use of testChdir to standard library's t.Chdir, remove testChdir function from codebase (#37334)
* Replace use of `testChdir` with `t.Chdir`

* Update tests to use temporary directories with copied content, instead of using directories in the repo directly.

* Remove stacks copy of testChdir function

This has been replaced with t.Chdir from the standard library

* Replace remaining simple usage of testChdir

* Update guidance for using `tempWorkingDir`

* Replace use of testChdir in a function reused in a single test

* Update comments to no longer recommend using testChdir

* Remove testChdir function!
2025-07-16 16:04:10 +01:00

47 lines
932 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package command
import (
"os"
"reflect"
"testing"
)
func TestPluginPath(t *testing.T) {
td := testTempDir(t)
defer os.RemoveAll(td)
t.Chdir(td)
pluginPath := []string{"a", "b", "c"}
m := Meta{}
if err := m.storePluginPath(pluginPath); err != nil {
t.Fatal(err)
}
restoredPath, err := m.loadPluginPath()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(pluginPath, restoredPath) {
t.Fatalf("expected plugin path %#v, got %#v", pluginPath, restoredPath)
}
}
func TestInternalProviders(t *testing.T) {
m := Meta{}
internal := m.internalProviders()
tfProvider, err := internal["terraform"]()
if err != nil {
t.Fatal(err)
}
schema := tfProvider.GetProviderSchema()
_, found := schema.DataSources["terraform_remote_state"]
if !found {
t.Errorf("didn't find terraform_remote_state in internal \"terraform\" provider")
}
}