github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/tabulate/tabulate_tf_test.go (about) 1 package tabulate 2 3 import ( 4 "testing" 5 6 "github.com/lmorg/murex/lang/types" 7 "github.com/lmorg/murex/test" 8 ) 9 10 var ( 11 inTf = `Usage: terraform apply [options] [DIR-OR-PLAN] 12 13 Builds or changes infrastructure according to Terraform configuration 14 files in DIR. 15 16 By default, apply scans the current directory for the configuration 17 and applies the changes appropriately. However, a path to another 18 configuration or an execution plan can be provided. Execution plans can be 19 used to only execute a pre-determined set of actions. 20 21 Options: 22 23 -auto-approve Skip interactive approval of plan before applying. 24 25 -backup=path Path to backup the existing state file before 26 modifying. Defaults to the "-state-out" path with 27 ".backup" extension. Set to "-" to disable backup. 28 29 -compact-warnings If Terraform produces any warnings that are not 30 accompanied by errors, show them in a more compact 31 form that includes only the summary messages. 32 33 -lock=true Lock the state file when locking is supported. 34 35 -lock-timeout=0s Duration to retry a state lock. 36 37 -input=true Ask for input for variables if not directly set. 38 39 -no-color If specified, output won't contain any color. 40 41 -parallelism=n Limit the number of parallel resource operations. 42 Defaults to 10. 43 44 -refresh=true Update state prior to checking for differences. This 45 has no effect if a plan file is given to apply. 46 47 -state=path Path to read and save state (unless state-out 48 is specified). Defaults to "terraform.tfstate". 49 50 -state-out=path Path to write state to that is different than 51 "-state". This can be used to preserve the old 52 state. 53 54 -target=resource Resource to target. Operation will be limited to this 55 resource and its dependencies. This flag can be used 56 multiple times. 57 58 -var 'foo=bar' Set a variable in the Terraform configuration. This 59 flag can be set multiple times. 60 61 -var-file=foo Set variables in the Terraform configuration from 62 a file. If "terraform.tfvars" or any ".auto.tfvars" 63 files are present, they will be automatically loaded.` 64 65 csvTfNoFlags = `Builds or changes infrastructure according to Terraform configuration 66 files in DIR. 67 "By default, apply scans the current directory for the configuration" 68 "and applies the changes appropriately. However, a path to another" 69 configuration or an execution plan can be provided. Execution plans can be 70 used to only execute a pre-determined set of actions. 71 -auto-approve,Skip interactive approval of plan before applying. 72 -backup=path,Path to backup the existing state file before 73 "modifying. Defaults to the ""-state-out"" path with" 74 """.backup"" extension. Set to ""-"" to disable backup." 75 -compact-warnings,If Terraform produces any warnings that are not 76 "accompanied by errors, show them in a more compact" 77 form that includes only the summary messages. 78 -lock=true,Lock the state file when locking is supported. 79 -lock-timeout=0s,Duration to retry a state lock. 80 -input=true,Ask for input for variables if not directly set. 81 -no-color,"If specified, output won't contain any color." 82 -parallelism=n,Limit the number of parallel resource operations. 83 Defaults to 10. 84 -refresh=true,Update state prior to checking for differences. This 85 has no effect if a plan file is given to apply. 86 -state=path,Path to read and save state (unless state-out 87 "is specified). Defaults to ""terraform.tfstate""." 88 -state-out=path,Path to write state to that is different than 89 """-state"". This can be used to preserve the old" 90 state. 91 -target=resource,Resource to target. Operation will be limited to this 92 resource and its dependencies. This flag can be used 93 multiple times. 94 -var 'foo=bar',Set a variable in the Terraform configuration. This 95 flag can be set multiple times. 96 -var-file=foo,Set variables in the Terraform configuration from 97 "a file. If ""terraform.tfvars"" or any "".auto.tfvars""" 98 "files are present, they will be automatically loaded." 99 ` 100 101 csvTfKeyValue = `-auto-approve,Skip interactive approval of plan before applying. 102 -backup=path,Path to backup the existing state file before 103 -compact-warnings,If Terraform produces any warnings that are not 104 -lock=true,Lock the state file when locking is supported. 105 -lock-timeout=0s,Duration to retry a state lock. 106 -input=true,Ask for input for variables if not directly set. 107 -no-color,"If specified, output won't contain any color." 108 -parallelism=n,Limit the number of parallel resource operations. 109 -refresh=true,Update state prior to checking for differences. This 110 -state=path,Path to read and save state (unless state-out 111 -state-out=path,Path to write state to that is different than 112 -target=resource,Resource to target. Operation will be limited to this 113 -var 'foo=bar',Set a variable in the Terraform configuration. This 114 -var-file=foo,Set variables in the Terraform configuration from 115 ` 116 117 csvTfColumnWraps = `-auto-approve,Skip interactive approval of plan before applying. 118 -backup=path,"Path to backup the existing state file before modifying. Defaults to the ""-state-out"" path with "".backup"" extension. Set to ""-"" to disable backup." 119 -compact-warnings,"If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages." 120 -lock=true,Lock the state file when locking is supported. 121 -lock-timeout=0s,Duration to retry a state lock. 122 -input=true,Ask for input for variables if not directly set. 123 -no-color,"If specified, output won't contain any color." 124 -parallelism=n,Limit the number of parallel resource operations. Defaults to 10. 125 -refresh=true,Update state prior to checking for differences. This has no effect if a plan file is given to apply. 126 -state=path,"Path to read and save state (unless state-out is specified). Defaults to ""terraform.tfstate""." 127 -state-out=path,"Path to write state to that is different than ""-state"". This can be used to preserve the old state." 128 -target=resource,Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times. 129 -var 'foo=bar',Set a variable in the Terraform configuration. This flag can be set multiple times. 130 -var-file=foo,"Set variables in the Terraform configuration from a file. If ""terraform.tfvars"" or any "".auto.tfvars"" files are present, they will be automatically loaded." 131 ` 132 133 jsonTfNoFlags = `{"-auto-approve":"Skip interactive approval of plan before applying.","-backup=path":"Path to backup the existing state file before","-compact-warnings":"If Terraform produces any warnings that are not","-input=true":"Ask for input for variables if not directly set.","-lock-timeout=0s":"Duration to retry a state lock.","-lock=true":"Lock the state file when locking is supported.","-no-color":"If specified, output won't contain any color.","-parallelism=n":"Limit the number of parallel resource operations.","-refresh=true":"Update state prior to checking for differences. This","-state-out=path":"Path to write state to that is different than","-state=path":"Path to read and save state (unless state-out","-target=resource":"Resource to target. Operation will be limited to this","-var 'foo=bar'":"Set a variable in the Terraform configuration. This","-var-file=foo":"Set variables in the Terraform configuration from"}` 134 135 jsonTfColumnWraps = `{"-auto-approve":"Skip interactive approval of plan before applying.","-backup=path":"Path to backup the existing state file before modifying. Defaults to the \"-state-out\" path with \".backup\" extension. Set to \"-\" to disable backup.","-compact-warnings":"If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.","-input=true":"Ask for input for variables if not directly set.","-lock-timeout=0s":"Duration to retry a state lock.","-lock=true":"Lock the state file when locking is supported.","-no-color":"If specified, output won't contain any color.","-parallelism=n":"Limit the number of parallel resource operations. Defaults to 10.","-refresh=true":"Update state prior to checking for differences. This has no effect if a plan file is given to apply.","-state-out=path":"Path to write state to that is different than \"-state\". This can be used to preserve the old state.","-state=path":"Path to read and save state (unless state-out is specified). Defaults to \"terraform.tfstate\".","-target=resource":"Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.","-var 'foo=bar'":"Set a variable in the Terraform configuration. This flag can be set multiple times.","-var-file=foo":"Set variables in the Terraform configuration from a file. If \"terraform.tfvars\" or any \".auto.tfvars\" files are present, they will be automatically loaded."}` 136 ) 137 138 func TestTabulateTerraform(t *testing.T) { 139 test.RunMethodTest(t, 140 cmdTabulate, "tabulate", 141 inTf, 142 types.Generic, 143 []string{}, 144 csvTfNoFlags, 145 nil, 146 ) 147 148 test.RunMethodTest(t, 149 cmdTabulate, "tabulate", 150 inTf, 151 types.Generic, 152 []string{fKeyVal}, 153 csvTfKeyValue, 154 nil, 155 ) 156 157 test.RunMethodTest(t, 158 cmdTabulate, "tabulate", 159 inTf, 160 types.Generic, 161 []string{fColumnWraps, fKeyVal}, 162 csvTfColumnWraps, 163 nil, 164 ) 165 166 test.RunMethodTest(t, 167 cmdTabulate, "tabulate", 168 inTf, 169 types.Generic, 170 []string{fMap}, 171 jsonTfNoFlags, 172 nil, 173 ) 174 175 test.RunMethodTest(t, 176 cmdTabulate, "tabulate", 177 inTf, 178 types.Generic, 179 []string{fColumnWraps, fMap}, 180 jsonTfColumnWraps, 181 nil, 182 ) 183 }