github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/commands/build/compose_test.go (about)

     1  package build
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/app/internal/packager"
     7  	"github.com/docker/buildx/build"
     8  	"gotest.tools/assert"
     9  )
    10  
    11  func Test_parseCompose(t *testing.T) {
    12  	tests := []struct {
    13  		name    string
    14  		service string
    15  		want    build.Options
    16  	}{
    17  		{
    18  			name:    "simple",
    19  			service: "web",
    20  			want: build.Options{
    21  				Inputs: build.Inputs{
    22  					ContextPath:    "testdata/web",
    23  					DockerfilePath: "testdata/web/Dockerfile",
    24  				},
    25  				Tags: []string{"frontend"},
    26  			},
    27  		},
    28  		{
    29  			name:    "context",
    30  			service: "web",
    31  			want: build.Options{
    32  				Inputs: build.Inputs{
    33  					ContextPath:    "testdata/web",
    34  					DockerfilePath: "testdata/web/Dockerfile.custom",
    35  				},
    36  			},
    37  		},
    38  		{
    39  			name:    "withargs",
    40  			service: "web",
    41  			want: build.Options{
    42  				Inputs: build.Inputs{
    43  					ContextPath:    "testdata/web",
    44  					DockerfilePath: "testdata/web/Dockerfile",
    45  				},
    46  				BuildArgs: map[string]string{"foo": "bar"},
    47  			},
    48  		},
    49  	}
    50  	for _, tt := range tests {
    51  		t.Run(tt.name, func(t *testing.T) {
    52  			app, err := packager.Extract("testdata/" + tt.name)
    53  			assert.NilError(t, err)
    54  			got, _, err := parseCompose(app, "testdata", newBuildOptions())
    55  			assert.NilError(t, err)
    56  			_, ok := got["dontwant"]
    57  			assert.Assert(t, !ok, "parseCompose() should have excluded 'dontwant' service")
    58  			opt, ok := got[tt.service]
    59  			assert.Assert(t, ok, "parseCompose() error = %s not converted into a build.Options", tt.service)
    60  			assert.DeepEqual(t, opt, tt.want)
    61  		})
    62  	}
    63  }