bake: fix hcl tests layout

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
pull/539/head
Tonis Tiigi 4 years ago
parent 7d2e30096b
commit 0e9066f6ed

@ -7,10 +7,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestParseHCL(t *testing.T) { func TestHCLBasic(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("Basic", func(t *testing.T) {
dt := []byte(` dt := []byte(`
group "default" { group "default" {
targets = ["db", "webapp"] targets = ["db", "webapp"]
@ -66,9 +64,9 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, c.Targets[3].Name, "webapp-plus") require.Equal(t, c.Targets[3].Name, "webapp-plus")
require.Equal(t, 1, len(c.Targets[3].Args)) require.Equal(t, 1, len(c.Targets[3].Args))
require.Equal(t, map[string]string{"IAMCROSS": "true"}, c.Targets[3].Args) require.Equal(t, map[string]string{"IAMCROSS": "true"}, c.Targets[3].Args)
}) }
t.Run("BasicInJSON", func(t *testing.T) { func TestHCLBasicInJSON(t *testing.T) {
dt := []byte(` dt := []byte(`
{ {
"group": { "group": {
@ -126,9 +124,9 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, c.Targets[3].Name, "webapp-plus") require.Equal(t, c.Targets[3].Name, "webapp-plus")
require.Equal(t, 1, len(c.Targets[3].Args)) require.Equal(t, 1, len(c.Targets[3].Args))
require.Equal(t, map[string]string{"IAMCROSS": "true"}, c.Targets[3].Args) require.Equal(t, map[string]string{"IAMCROSS": "true"}, c.Targets[3].Args)
}) }
t.Run("WithFunctions", func(t *testing.T) { func TestHCLWithFunctions(t *testing.T) {
dt := []byte(` dt := []byte(`
group "default" { group "default" {
targets = ["webapp"] targets = ["webapp"]
@ -151,9 +149,9 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, 1, len(c.Targets)) require.Equal(t, 1, len(c.Targets))
require.Equal(t, c.Targets[0].Name, "webapp") require.Equal(t, c.Targets[0].Name, "webapp")
require.Equal(t, "124", c.Targets[0].Args["buildno"]) require.Equal(t, "124", c.Targets[0].Args["buildno"])
}) }
t.Run("WithUserDefinedFunctions", func(t *testing.T) { func TestHCLWithUserDefinedFunctions(t *testing.T) {
dt := []byte(` dt := []byte(`
function "increment" { function "increment" {
params = [number] params = [number]
@ -181,9 +179,9 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, 1, len(c.Targets)) require.Equal(t, 1, len(c.Targets))
require.Equal(t, c.Targets[0].Name, "webapp") require.Equal(t, c.Targets[0].Name, "webapp")
require.Equal(t, "124", c.Targets[0].Args["buildno"]) require.Equal(t, "124", c.Targets[0].Args["buildno"])
}) }
t.Run("WithVariables", func(t *testing.T) { func TestHCLWithVariables(t *testing.T) {
dt := []byte(` dt := []byte(`
variable "BUILD_NUMBER" { variable "BUILD_NUMBER" {
default = "123" default = "123"
@ -223,9 +221,9 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, 1, len(c.Targets)) require.Equal(t, 1, len(c.Targets))
require.Equal(t, c.Targets[0].Name, "webapp") require.Equal(t, c.Targets[0].Name, "webapp")
require.Equal(t, "456", c.Targets[0].Args["buildno"]) require.Equal(t, "456", c.Targets[0].Args["buildno"])
}) }
t.Run("WithIncorrectVariables", func(t *testing.T) { func TesstHCLWithIncorrectVariables(t *testing.T) {
dt := []byte(` dt := []byte(`
variable "DEFAULT_BUILD_NUMBER" { variable "DEFAULT_BUILD_NUMBER" {
default = "1" default = "1"
@ -249,9 +247,9 @@ func TestParseHCL(t *testing.T) {
_, err := ParseFile(dt, "docker-bake.hcl") _, err := ParseFile(dt, "docker-bake.hcl")
require.Error(t, err) require.Error(t, err)
require.Contains(t, err.Error(), "docker-bake.hcl:7,17-37: Variables not allowed; Variables may not be used here.") require.Contains(t, err.Error(), "docker-bake.hcl:7,17-37: Variables not allowed; Variables may not be used here.")
}) }
t.Run("WithVariablesInFunctions", func(t *testing.T) { func TestHCLWithVariablesInFunctions(t *testing.T) {
dt := []byte(` dt := []byte(`
variable "REPO" { variable "REPO" {
default = "user/repo" default = "user/repo"
@ -281,9 +279,9 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, 1, len(c.Targets)) require.Equal(t, 1, len(c.Targets))
require.Equal(t, c.Targets[0].Name, "webapp") require.Equal(t, c.Targets[0].Name, "webapp")
require.Equal(t, []string{"docker/buildx:v1"}, c.Targets[0].Tags) require.Equal(t, []string{"docker/buildx:v1"}, c.Targets[0].Tags)
}) }
t.Run("MultiFileSharedVariables", func(t *testing.T) { func TestHCLMultiFileSharedVariables(t *testing.T) {
dt := []byte(` dt := []byte(`
variable "FOO" { variable "FOO" {
default = "abc" default = "abc"
@ -324,5 +322,4 @@ func TestParseHCL(t *testing.T) {
require.Equal(t, c.Targets[0].Name, "app") require.Equal(t, c.Targets[0].Name, "app")
require.Equal(t, "pre-def", c.Targets[0].Args["v1"]) require.Equal(t, "pre-def", c.Targets[0].Args["v1"])
require.Equal(t, "def-post", c.Targets[0].Args["v2"]) require.Equal(t, "def-post", c.Targets[0].Args["v2"])
})
} }

Loading…
Cancel
Save