diff --git a/internal/wrapper/checkargs.go b/internal/wrapper/checkargs.go index c2031e4..1c6c6df 100644 --- a/internal/wrapper/checkargs.go +++ b/internal/wrapper/checkargs.go @@ -10,14 +10,13 @@ func checkStateCommand(args []string, version *semver.Version) ([]string, error) versionImport, _ := semver.NewConstraint(">= 1.5.0") versionMoved, _ := semver.NewConstraint(">= 1.1.0") versionImport.Check(version) - if checkArgsExists(args, "state") >= 0 && - checkArgsExists(args, "import") >= 0 && + if checkArgsExists(args, "import") >= 0 && versionImport.Check(version) { force_pos := checkArgsExists(args, "--force") if force_pos > 0 { return append(args[:force_pos], args[force_pos+1:]...), nil } else { - return args, errors.New("--force flag is required for the 'state import' command. Consider using Terraform configuration import block instead") + return args, errors.New("--force flag is required for the 'import' command. Consider using Terraform configuration import block instead") } } diff --git a/internal/wrapper/checkargs_test.go b/internal/wrapper/checkargs_test.go index 84f52cb..9ba6327 100644 --- a/internal/wrapper/checkargs_test.go +++ b/internal/wrapper/checkargs_test.go @@ -9,29 +9,29 @@ import ( func TestCheckStateCommand(t *testing.T) { t.Run("Valid state import command with --force flag on 1.5.0", func(t *testing.T) { - args := []string{"state", "import", "--force"} + args := []string{"import", "--force"} version, _ := semver.NewVersion("1.5.0") result, err := checkStateCommand(args, version) - if err != nil || !slices.Equal(result, []string{"state", "import"}) { + if err != nil || !slices.Equal(result, []string{"import"}) { t.Errorf("Expected no error, got: %v, %v", err, result) } }) t.Run("Valid state import command without --force flag on 1.4.7", func(t *testing.T) { - args := []string{"state", "import"} + args := []string{"import"} version, _ := semver.NewVersion("1.4.7") result, err := checkStateCommand(args, version) - if err != nil || !slices.Equal(result, []string{"state", "import"}) { + if err != nil || !slices.Equal(result, []string{"import"}) { t.Errorf("Expected no error, got: %v", err) } }) t.Run("Invalid state import command without --force flag on 1.5.0", func(t *testing.T) { - args := []string{"state", "import"} + args := []string{"import"} version, _ := semver.NewVersion("1.6.0") - result, err := checkStateCommand(args, version) + _, err := checkStateCommand(args, version) if err == nil { - t.Errorf("Expected error, got: %v, %v", err, result) + t.Errorf("Expected error, got: %v", err) } }) @@ -46,20 +46,16 @@ func TestCheckStateCommand(t *testing.T) { } func TestCheckArgsExists(t *testing.T) { - t.Run("Check 'state import --force' command", func(t *testing.T) { - args := []string{"state", "import", "--force"} - result := checkArgsExists(args, "state") + t.Run("Check 'import --force' command", func(t *testing.T) { + args := []string{"import", "--force"} + result := checkArgsExists(args, "import") if result != 0 { t.Errorf("Expected 0, got: %v", result) } - result = checkArgsExists(args, "import") + result = checkArgsExists(args, "--force") if result != 1 { t.Errorf("Expected 1, got: %v", result) } - result = checkArgsExists(args, "--force") - if result != 2 { - t.Errorf("Expected 2, got: %v", result) - } }) t.Run("Check 'state moved' command", func(t *testing.T) {