@@ -1629,6 +1629,69 @@ prompts.
16291629 })
16301630}
16311631
1632+ func TestInit_cloudConfigColorTokensProcessed (t * testing.T ) {
1633+ // This test verifies that when the error
1634+ // diagnostic detail contains color formatting tokens like [bold] and
1635+ // [reset], they are properly processed
1636+ // by the diagnostic formatter and do not appear as literal text in the
1637+ // output.
1638+ td := t .TempDir ()
1639+ testCopyDir (t , testFixturePath ("init-cloud-no-workspaces" ), td )
1640+ t .Chdir (td )
1641+
1642+ ui := cli .NewMockUi ()
1643+ view , done := testView (t )
1644+ c := & InitCommand {
1645+ Meta : Meta {
1646+ Ui : ui ,
1647+ View : view ,
1648+ },
1649+ }
1650+
1651+ args := []string {}
1652+ code := c .Run (args )
1653+ if code == 0 {
1654+ t .Fatalf ("expected error, got success\n %s" , done (t ).Stdout ())
1655+ }
1656+
1657+ gotStderr := done (t ).Stderr ()
1658+
1659+ expected := `
1660+ Error: failed to create backend alias to target "". The hostname is not in the correct format.
1661+
1662+
1663+ Error: Invalid workspaces configuration
1664+
1665+ on main.tf line 7, in terraform:
1666+ 7: cloud {
1667+
1668+ Missing workspace mapping strategy. Either workspace "tags" or "name" is
1669+ required.
1670+
1671+ The 'workspaces' block configures how Terraform CLI maps its workspaces for
1672+ this single
1673+ configuration to workspaces within an HCP Terraform or Terraform Enterprise
1674+ organization. Two strategies are available:
1675+
1676+ tags - A set of tags used to select remote HCP Terraform or Terraform
1677+ Enterprise workspaces to be used for this single
1678+ configuration. New workspaces will automatically be tagged with these tag
1679+ values. Generally, this
1680+ is the primary and recommended strategy to use. This option conflicts with
1681+ "name".
1682+
1683+ name - The name of a single HCP Terraform or Terraform Enterprise workspace
1684+ to be used with this configuration.
1685+ When configured, only the specified workspace can be used. This option
1686+ conflicts with "tags"
1687+ and with the TF_WORKSPACE environment variable.
1688+ `
1689+
1690+ if diff := cmp .Diff (gotStderr , expected ); diff != "" {
1691+ t .Errorf ("unexpected output (-got +expected):\n %s" , diff )
1692+ }
1693+ }
1694+
16321695// make sure inputFalse stops execution on migrate
16331696func TestInit_inputFalse (t * testing.T ) {
16341697 td := t .TempDir ()
0 commit comments