opentofu/internal/command/autocomplete_test.go
Andrei Ciobanu 25d652dece
-chdir unification with the workdir logic. Removal of workdir proxy methods from Meta (#3713)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-10 15:31:06 +02:00

44 lines
947 B
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package command
import (
"os"
"reflect"
"testing"
"github.com/mitchellh/cli"
"github.com/opentofu/opentofu/internal/command/workdir"
"github.com/posener/complete"
)
func TestMetaCompletePredictWorkspaceName(t *testing.T) {
// Create a temporary working directory that is empty
td := t.TempDir()
t.Chdir(td)
// make sure a vars file doesn't interfere
err := os.WriteFile(DefaultVarsFilename, nil, 0644)
if err != nil {
t.Fatal(err)
}
ui := new(cli.MockUi)
meta := &Meta{
WorkingDir: workdir.NewDir("."),
Ui: ui,
}
predictor := meta.completePredictWorkspaceName(t.Context())
got := predictor.Predict(complete.Args{
Last: "",
})
want := []string{"default"}
if !reflect.DeepEqual(got, want) {
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, want)
}
}