@ -4,6 +4,7 @@ import (
"context"
"context"
"os"
"os"
"sort"
"sort"
"strings"
"testing"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
@ -46,7 +47,7 @@ target "webapp" {
require . Nil ( t , m [ "webapp" ] . Pull )
require . Nil ( t , m [ "webapp" ] . Pull )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} )
} )
t . Run ( "InvalidTargetOverrides" , func ( t * testing . T ) {
t . Run ( "InvalidTargetOverrides" , func ( t * testing . T ) {
@ -87,7 +88,7 @@ target "webapp" {
require . Equal ( t , m [ "webapp" ] . Args [ "VAR_INHERITED" ] , "override" )
require . Equal ( t , m [ "webapp" ] . Args [ "VAR_INHERITED" ] , "override" )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} )
} )
// building leaf but overriding parent fields
// building leaf but overriding parent fields
@ -101,7 +102,7 @@ target "webapp" {
require . Equal ( t , m [ "webapp" ] . Args [ "VAR_INHERITED" ] , "override" )
require . Equal ( t , m [ "webapp" ] . Args [ "VAR_INHERITED" ] , "override" )
require . Equal ( t , m [ "webapp" ] . Args [ "VAR_BOTH" ] , "webapp" )
require . Equal ( t , m [ "webapp" ] . Args [ "VAR_BOTH" ] , "webapp" )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} )
} )
} )
} )
@ -113,7 +114,7 @@ target "webapp" {
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , "foo" , * m [ "webapp" ] . Context )
require . Equal ( t , "foo" , * m [ "webapp" ] . Context )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} )
} )
t . Run ( "NoCacheOverride" , func ( t * testing . T ) {
t . Run ( "NoCacheOverride" , func ( t * testing . T ) {
@ -121,7 +122,7 @@ target "webapp" {
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , false , * m [ "webapp" ] . NoCache )
require . Equal ( t , false , * m [ "webapp" ] . NoCache )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} )
} )
t . Run ( "PullOverride" , func ( t * testing . T ) {
t . Run ( "PullOverride" , func ( t * testing . T ) {
@ -129,12 +130,12 @@ target "webapp" {
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , false , * m [ "webapp" ] . Pull )
require . Equal ( t , false , * m [ "webapp" ] . Pull )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} )
} )
t . Run ( "PatternOverride" , func ( t * testing . T ) {
t . Run ( "PatternOverride" , func ( t * testing . T ) {
// same check for two cases
// same check for two cases
multiTargetCheck := func ( t * testing . T , m map [ string ] * Target , g [ ] * Group , err error ) {
multiTargetCheck := func ( t * testing . T , m map [ string ] * Target , g map [ string ] * Group , err error ) {
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , "foo" , * m [ "webapp" ] . Dockerfile )
require . Equal ( t , "foo" , * m [ "webapp" ] . Dockerfile )
@ -142,15 +143,15 @@ target "webapp" {
require . Equal ( t , "foo" , * m [ "webDEP" ] . Dockerfile )
require . Equal ( t , "foo" , * m [ "webDEP" ] . Dockerfile )
require . Equal ( t , "webDEP" , m [ "webDEP" ] . Args [ "VAR_INHERITED" ] )
require . Equal ( t , "webDEP" , m [ "webDEP" ] . Args [ "VAR_INHERITED" ] )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
sort . Strings ( g [ 0 ] . Targets )
sort . Strings ( g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "webDEP" , "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webDEP" , "webapp" } , g [ "default" ] . Targets )
}
}
cases := [ ] struct {
cases := [ ] struct {
name string
name string
targets [ ] string
targets [ ] string
overrides [ ] string
overrides [ ] string
check func ( * testing . T , map [ string ] * Target , [ ] * Group , error )
check func ( * testing . T , map [ string ] * Target , map [ string ] * Group , error )
} {
} {
{
{
name : "multi target single pattern" ,
name : "multi target single pattern" ,
@ -168,20 +169,20 @@ target "webapp" {
name : "single target" ,
name : "single target" ,
targets : [ ] string { "webapp" } ,
targets : [ ] string { "webapp" } ,
overrides : [ ] string { "web*.dockerfile=foo" } ,
overrides : [ ] string { "web*.dockerfile=foo" } ,
check : func ( t * testing . T , m map [ string ] * Target , g [ ] * Group , err error ) {
check : func ( t * testing . T , m map [ string ] * Target , g map [ string ] * Group , err error ) {
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "foo" , * m [ "webapp" ] . Dockerfile )
require . Equal ( t , "foo" , * m [ "webapp" ] . Dockerfile )
require . Equal ( t , "webDEP" , m [ "webapp" ] . Args [ "VAR_INHERITED" ] )
require . Equal ( t , "webDEP" , m [ "webapp" ] . Args [ "VAR_INHERITED" ] )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "webapp" } , g [ "default" ] . Targets )
} ,
} ,
} ,
} ,
{
{
name : "nomatch" ,
name : "nomatch" ,
targets : [ ] string { "webapp" } ,
targets : [ ] string { "webapp" } ,
overrides : [ ] string { "nomatch*.dockerfile=foo" } ,
overrides : [ ] string { "nomatch*.dockerfile=foo" } ,
check : func ( t * testing . T , m map [ string ] * Target , g [ ] * Group , err error ) {
check : func ( t * testing . T , m map [ string ] * Target , g map [ string ] * Group , err error ) {
// NOTE: I am unsure whether failing to match should always error out
// NOTE: I am unsure whether failing to match should always error out
// instead of simply skipping that override.
// instead of simply skipping that override.
// Let's enforce the error and we can relax it later if users complain.
// Let's enforce the error and we can relax it later if users complain.
@ -303,8 +304,8 @@ services:
require . Equal ( t , "12" , m [ "webapp" ] . Args [ "buildno2" ] )
require . Equal ( t , "12" , m [ "webapp" ] . Args [ "buildno2" ] )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
sort . Strings ( g [ 0 ] . Targets )
sort . Strings ( g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "db" , "newservice" , "webapp" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "db" , "newservice" , "webapp" } , g [ "default" ] . Targets )
}
}
func TestReadTargetsWithDotCompose ( t * testing . T ) {
func TestReadTargetsWithDotCompose ( t * testing . T ) {
@ -364,8 +365,8 @@ services:
require . Equal ( t , "12" , m [ "web_app" ] . Args [ "buildno2" ] )
require . Equal ( t , "12" , m [ "web_app" ] . Args [ "buildno2" ] )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
sort . Strings ( g [ 0 ] . Targets )
sort . Strings ( g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "web_app" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "web_app" } , g [ "default" ] . Targets )
}
}
func TestHCLCwdPrefix ( t * testing . T ) {
func TestHCLCwdPrefix ( t * testing . T ) {
@ -392,7 +393,7 @@ func TestHCLCwdPrefix(t *testing.T) {
require . Equal ( t , "foo" , * m [ "app" ] . Context )
require . Equal ( t , "foo" , * m [ "app" ] . Context )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "app" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "app" } , g [ "default" ] . Targets )
}
}
func TestOverrideMerge ( t * testing . T ) {
func TestOverrideMerge ( t * testing . T ) {
@ -696,7 +697,7 @@ target "image" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "image" } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "image" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "default" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
}
}
@ -717,8 +718,9 @@ target "image" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "foo" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
}
}
@ -742,15 +744,17 @@ target "image" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "foo" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
m , g , err = ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" , "foo" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" , "foo" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "foo" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
require . Equal ( t , "test" , * m [ "image" ] . Dockerfile )
}
}
@ -829,7 +833,7 @@ services:
m , g , err := ReadTargets ( ctx , [ ] File { fhcl } , [ ] string { "default" } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { fhcl } , [ ] string { "default" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "default" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m [ "image" ] . Outputs ) )
require . Equal ( t , 1 , len ( m [ "image" ] . Outputs ) )
require . Equal ( t , "type=docker" , m [ "image" ] . Outputs [ 0 ] )
require . Equal ( t , "type=docker" , m [ "image" ] . Outputs [ 0 ] )
@ -837,7 +841,7 @@ services:
m , g , err = ReadTargets ( ctx , [ ] File { fhcl } , [ ] string { "image-release" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fhcl } , [ ] string { "image-release" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "image-release" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "image-release" } , g [ "default" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m [ "image-release" ] . Outputs ) )
require . Equal ( t , 1 , len ( m [ "image-release" ] . Outputs ) )
require . Equal ( t , "type=image,push=true" , m [ "image-release" ] . Outputs [ 0 ] )
require . Equal ( t , "type=image,push=true" , m [ "image-release" ] . Outputs [ 0 ] )
@ -845,7 +849,7 @@ services:
m , g , err = ReadTargets ( ctx , [ ] File { fhcl } , [ ] string { "image" , "image-release" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fhcl } , [ ] string { "image" , "image-release" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "image" , "image-release" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "image" , "image-release" } , g [ "default" ] . Targets )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , "." , * m [ "image" ] . Context )
require . Equal ( t , "." , * m [ "image" ] . Context )
require . Equal ( t , 1 , len ( m [ "image-release" ] . Outputs ) )
require . Equal ( t , 1 , len ( m [ "image-release" ] . Outputs ) )
@ -854,22 +858,22 @@ services:
m , g , err = ReadTargets ( ctx , [ ] File { fyml , fhcl } , [ ] string { "default" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fyml , fhcl } , [ ] string { "default" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "default" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "." , * m [ "image" ] . Context )
require . Equal ( t , "." , * m [ "image" ] . Context )
m , g , err = ReadTargets ( ctx , [ ] File { fjson } , [ ] string { "default" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fjson } , [ ] string { "default" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "image" } , g [ "default" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "." , * m [ "image" ] . Context )
require . Equal ( t , "." , * m [ "image" ] . Context )
m , g , err = ReadTargets ( ctx , [ ] File { fyml } , [ ] string { "default" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fyml } , [ ] string { "default" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
sort . Strings ( g [ 0 ] . Targets )
sort . Strings ( g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "addon" , "aws" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "addon" , "aws" } , g [ "default" ] . Targets )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , "./Dockerfile" , * m [ "addon" ] . Dockerfile )
require . Equal ( t , "./Dockerfile" , * m [ "addon" ] . Dockerfile )
require . Equal ( t , "./aws.Dockerfile" , * m [ "aws" ] . Dockerfile )
require . Equal ( t , "./aws.Dockerfile" , * m [ "aws" ] . Dockerfile )
@ -877,8 +881,8 @@ services:
m , g , err = ReadTargets ( ctx , [ ] File { fyml , fhcl } , [ ] string { "addon" , "aws" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fyml , fhcl } , [ ] string { "addon" , "aws" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
sort . Strings ( g [ 0 ] . Targets )
sort . Strings ( g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "addon" , "aws" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "addon" , "aws" } , g [ "default" ] . Targets )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , "./Dockerfile" , * m [ "addon" ] . Dockerfile )
require . Equal ( t , "./Dockerfile" , * m [ "addon" ] . Dockerfile )
require . Equal ( t , "./aws.Dockerfile" , * m [ "aws" ] . Dockerfile )
require . Equal ( t , "./aws.Dockerfile" , * m [ "aws" ] . Dockerfile )
@ -886,8 +890,8 @@ services:
m , g , err = ReadTargets ( ctx , [ ] File { fyml , fhcl } , [ ] string { "addon" , "aws" , "image" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { fyml , fhcl } , [ ] string { "addon" , "aws" , "image" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
sort . Strings ( g [ 0 ] . Targets )
sort . Strings ( g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "addon" , "aws" , "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "addon" , "aws" , "image" } , g [ "default" ] . Targets )
require . Equal ( t , 3 , len ( m ) )
require . Equal ( t , 3 , len ( m ) )
require . Equal ( t , "." , * m [ "image" ] . Context )
require . Equal ( t , "." , * m [ "image" ] . Context )
require . Equal ( t , "./Dockerfile" , * m [ "addon" ] . Dockerfile )
require . Equal ( t , "./Dockerfile" , * m [ "addon" ] . Dockerfile )
@ -913,15 +917,17 @@ target "image" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "foo" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "foo" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
m , g , err = ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" , "foo" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" , "foo" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "foo" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "foo" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
}
}
@ -945,16 +951,18 @@ target "image" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "foo" , "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "foo" , "image" } , g [ "foo" ] . Targets )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
require . Equal ( t , "type=docker" , m [ "image" ] . Outputs [ 0 ] )
require . Equal ( t , "type=docker" , m [ "image" ] . Outputs [ 0 ] )
m , g , err = ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" , "image" } , nil , nil )
m , g , err = ReadTargets ( ctx , [ ] File { f } , [ ] string { "foo" , "image" } , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 2 , len ( g ) )
require . Equal ( t , [ ] string { "foo" , "image" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "foo" , "image" } , g [ "default" ] . Targets )
require . Equal ( t , [ ] string { "foo" , "image" } , g [ "foo" ] . Targets )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
require . Equal ( t , "bar" , * m [ "foo" ] . Dockerfile )
require . Equal ( t , "type=docker" , m [ "image" ] . Outputs [ 0 ] )
require . Equal ( t , "type=docker" , m [ "image" ] . Outputs [ 0 ] )
@ -1015,7 +1023,7 @@ target "d" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "d" } , tt . overrides , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "d" } , tt . overrides , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "d" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "d" } , g [ "default" ] . Targets )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , 1 , len ( m ) )
require . Equal ( t , tt . want , m [ "d" ] . Args )
require . Equal ( t , tt . want , m [ "d" ] . Args )
} )
} )
@ -1087,7 +1095,7 @@ group "default" {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "default" } , tt . overrides , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { "default" } , tt . overrides , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , [ ] string { "child1" , "child2" } , g [ 0 ] . Targets )
require . Equal ( t , [ ] string { "child1" , "child2" } , g [ "default" ] . Targets )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , 2 , len ( m ) )
require . Equal ( t , tt . wantch1 , m [ "child1" ] . Args )
require . Equal ( t , tt . wantch1 , m [ "child1" ] . Args )
require . Equal ( t , [ ] string { "type=docker" } , m [ "child1" ] . Outputs )
require . Equal ( t , [ ] string { "type=docker" } , m [ "child1" ] . Outputs )
@ -1184,44 +1192,67 @@ target "f" {
} ` ) }
} ` ) }
cases := [ ] struct {
cases := [ ] struct {
name string
names [ ] string
targets [ ] string
targets [ ] string
ntargets int
groups [ ] string
count int
} {
} {
{
{
name : "a" ,
names : [ ] string { "a" } ,
targets : [ ] string { "b" , "c" } ,
targets : [ ] string { "a" } ,
ntargets : 1 ,
groups : [ ] string { "default" , "a" , "b" , "c" } ,
count : 1 ,
} ,
} ,
{
{
name : "b" ,
names : [ ] string { "b" } ,
targets : [ ] string { "d" } ,
targets : [ ] string { "b" } ,
ntargets : 1 ,
groups : [ ] string { "default" , "b" } ,
count : 1 ,
} ,
} ,
{
{
name : "c" ,
names : [ ] string { "c" } ,
targets : [ ] string { "b" } ,
targets : [ ] string { "c" } ,
ntargets : 1 ,
groups : [ ] string { "default" , "b" , "c" } ,
count : 1 ,
} ,
} ,
{
{
name : "d" ,
names : [ ] string { "d" } ,
targets : [ ] string { "d" } ,
targets : [ ] string { "d" } ,
ntargets : 1 ,
groups : [ ] string { "default" } ,
count : 1 ,
} ,
} ,
{
{
name : "e" ,
names : [ ] string { "e" } ,
targets : [ ] string { "a" , "f" } ,
targets : [ ] string { "e" } ,
ntargets : 2 ,
groups : [ ] string { "default" , "a" , "b" , "c" , "e" } ,
count : 2 ,
} ,
{
names : [ ] string { "a" , "e" } ,
targets : [ ] string { "a" , "e" } ,
groups : [ ] string { "default" , "a" , "b" , "c" , "e" } ,
count : 2 ,
} ,
} ,
}
}
for _ , tt := range cases {
for _ , tt := range cases {
tt := tt
tt := tt
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( strings. Join ( tt. name s, "+" ) , func ( t * testing . T ) {
m , g , err := ReadTargets ( ctx , [ ] File { f } , [ ] string { tt . name } , nil , nil )
m , g , err := ReadTargets ( ctx , [ ] File { f } , tt . names , nil , nil )
require . NoError ( t , err )
require . NoError ( t , err )
require . Equal ( t , 1 , len ( g ) )
require . Equal ( t , tt . targets , g [ 0 ] . Targets )
var gnames [ ] string
require . Equal ( t , tt . ntargets , len ( m ) )
for _ , g := range g {
gnames = append ( gnames , g . Name )
}
sort . Strings ( gnames )
sort . Strings ( tt . groups )
require . Equal ( t , tt . groups , gnames )
sort . Strings ( g [ "default" ] . Targets )
sort . Strings ( tt . targets )
require . Equal ( t , tt . targets , g [ "default" ] . Targets )
require . Equal ( t , tt . count , len ( m ) )
require . Equal ( t , "." , * m [ "d" ] . Context )
require . Equal ( t , "." , * m [ "d" ] . Context )
require . Equal ( t , "./testdockerfile" , * m [ "d" ] . Dockerfile )
require . Equal ( t , "./testdockerfile" , * m [ "d" ] . Dockerfile )
} )
} )