@@ -74,6 +74,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){
7474 testBakeLoadPush ,
7575 testListTargets ,
7676 testListVariables ,
77+ testListTypedVariables ,
7778 testBakeCallCheck ,
7879 testBakeCallCheckFlag ,
7980 testBakeCallMetadata ,
@@ -1737,7 +1738,93 @@ target "default" {
17371738 )
17381739 require .NoError (t , err , out )
17391740
1740- require .Equal (t , "VARIABLE\t VALUE\t DESCRIPTION\n abc\t \t <null>\t \n def\t \t \t \n foo\t \t bar\t This is foo" , strings .TrimSpace (out ))
1741+ require .Equal (t , "VARIABLE\t TYPE\t VALUE\t DESCRIPTION\n abc\t \t \t <null>\t \n def\t \t \t \t \n foo\t \t \t bar\t This is foo" , strings .TrimSpace (out ))
1742+ }
1743+
1744+ func testListTypedVariables (t * testing.T , sb integration.Sandbox ) {
1745+ bakefile := []byte (`
1746+ variable "abc" {
1747+ type = string
1748+ default = "bar"
1749+ description = "This is abc"
1750+ }
1751+ variable "def" {
1752+ type = string
1753+ description = "simple type, no default"
1754+ }
1755+ variable "ghi" {
1756+ type = number
1757+ default = 99
1758+ description = "simple type w/ default"
1759+ }
1760+ variable "jkl" {
1761+ type = list(string)
1762+ default = ["hello"]
1763+ description = "collection with quoted strings"
1764+ }
1765+ variable "mno" {
1766+ type = list(number)
1767+ description = "collection, no default"
1768+ }
1769+ variable "pqr" {
1770+ type = tuple([number, string, bool])
1771+ default = [99, "99", true]
1772+ }
1773+ variable "stu" {
1774+ type = map(string)
1775+ default = {"foo": "bar"}
1776+ }
1777+ variable "vwx" {
1778+ type = set(bool)
1779+ default = null
1780+ description = "collection, null default"
1781+ }
1782+
1783+ // untyped, but previously didn't have its value output
1784+ variable "wxy" {
1785+ default = ["foo"]
1786+ description = "inferred tuple"
1787+ }
1788+ // untyped, but previously didn't have its value output
1789+ variable "xyz" {
1790+ default = {"foo": "bar"}
1791+ description = "inferred object"
1792+ }
1793+ // untyped, but previously didn't have its value output
1794+ variable "yza" {
1795+ default = true
1796+ description = "inferred bool"
1797+ }
1798+ target "default" {
1799+ }
1800+ ` )
1801+ dir := tmpdir (
1802+ t ,
1803+ fstest .CreateFile ("docker-bake.hcl" , bakefile , 0600 ),
1804+ )
1805+
1806+ out , err := bakeCmd (
1807+ sb ,
1808+ withDir (dir ),
1809+ withArgs ("--list=variables" ),
1810+ )
1811+ require .NoError (t , err , out )
1812+ require .Equal (t ,
1813+ "VARIABLE\t TYPE\t \t VALUE\t \t DESCRIPTION\n " +
1814+ "abc\t \t string\t \t bar\t \t This is abc\n " +
1815+ "def\t \t string\t \t <null>\t \t simple type, no default\n " +
1816+ "ghi\t \t number\t \t 99\t \t simple type w/ default\n " +
1817+ "jkl\t \t list of string\t [\" hello\" ]\t collection with quoted strings\n " +
1818+ "mno\t \t list of number\t <null>\t \t collection, no default\n " +
1819+ // the implementation for tuple's 'friendly name' is very basic
1820+ // and marked as TODO, so this may change/break at some point
1821+ "pqr\t \t tuple\t \t [99,\" 99\" ,true]\t \n " +
1822+ "stu\t \t map of string\t {\" foo\" :\" bar\" }\t \n " +
1823+ "vwx\t \t set of bool\t <null>\t \t collection, null default\n " +
1824+ "wxy\t \t \t \t [\" foo\" ]\t \t inferred tuple\n " +
1825+ "xyz\t \t \t \t {\" foo\" :\" bar\" }\t inferred object\n " +
1826+ "yza\t \t \t \t true\t \t inferred bool" ,
1827+ strings .TrimSpace (out ))
17411828}
17421829
17431830func testBakeCallCheck (t * testing.T , sb integration.Sandbox ) {
0 commit comments