This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test case to cover conversion of compose file into build.Option
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
- Loading branch information
Showing
14 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package commands | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/docker/app/internal/packager" | ||
"github.com/docker/buildx/build" | ||
"gotest.tools/assert" | ||
) | ||
|
||
func Test_parseCompose(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
service string | ||
want build.Options | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "simple", | ||
service: "web", | ||
want: build.Options{ | ||
Inputs: build.Inputs{ | ||
ContextPath: "testdata/web", | ||
DockerfilePath: "testdata/web/Dockerfile", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "context", | ||
service: "web", | ||
want: build.Options{ | ||
Inputs: build.Inputs{ | ||
ContextPath: "testdata/web", | ||
DockerfilePath: "testdata/web/Dockerfile.custom", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "withargs", | ||
service: "web", | ||
want: build.Options{ | ||
Inputs: build.Inputs{ | ||
ContextPath: "testdata/web", | ||
DockerfilePath: "testdata/web/Dockerfile", | ||
}, | ||
BuildArgs: map[string]string{"foo": "bar"}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
app, err := packager.Extract("testdata/" + tt.name) | ||
assert.NilError(t, err) | ||
|
||
got, err := parseCompose(app, buildOptions{}) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("parseCompose() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
opt, ok := got[tt.service] | ||
if !ok { | ||
t.Errorf("parseCompose() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(opt, tt.want) { | ||
t.Errorf("parseCompose() got = %v, want = %v", opt, tt.want) | ||
} | ||
}) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
internal/commands/testdata/context.dockerapp/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: "3.6" | ||
services: | ||
web: | ||
build: | ||
context: ./web | ||
dockerfile: Dockerfile.custom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 1.1.0-beta1 | ||
name: simple | ||
description: "new fancy webapp with microservices" | ||
maintainers: | ||
- name: John Developer | ||
email: john.dev@example.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
4 changes: 4 additions & 0 deletions
4
internal/commands/testdata/simple.dockerapp/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: "3.6" | ||
services: | ||
web: | ||
build: ./web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 1.1.0-beta1 | ||
name: simple | ||
description: "new fancy webapp with microservices" | ||
maintainers: | ||
- name: John Developer | ||
email: john.dev@example.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM scratch |
7 changes: 7 additions & 0 deletions
7
internal/commands/testdata/withargs.dockerapp/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: "3.6" | ||
services: | ||
web: | ||
build: | ||
context: ./web | ||
args: | ||
foo: bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 1.1.0-beta1 | ||
name: simple | ||
description: "new fancy webapp with microservices" | ||
maintainers: | ||
- name: John Developer | ||
email: john.dev@example.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |