Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
| ... | ... |
@@ -1195,3 +1195,23 @@ func TestBuldForbiddenContextPath(t *testing.T) {
|
| 1195 | 1195 |
} |
| 1196 | 1196 |
logDone("build - forbidden context path")
|
| 1197 | 1197 |
} |
| 1198 |
+ |
|
| 1199 |
+func TestBuildADDFileNotFound(t *testing.T) {
|
|
| 1200 |
+ name := "testbuildaddnotfound" |
|
| 1201 |
+ defer deleteImages(name) |
|
| 1202 |
+ ctx, err := fakeContext(`FROM scratch |
|
| 1203 |
+ ADD foo /usr/local/bar`, |
|
| 1204 |
+ map[string]string{"bar": "hello"})
|
|
| 1205 |
+ defer ctx.Close() |
|
| 1206 |
+ if err != nil {
|
|
| 1207 |
+ t.Fatal(err) |
|
| 1208 |
+ } |
|
| 1209 |
+ if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
|
| 1210 |
+ if !strings.Contains(err.Error(), "foo: no such file or directory") {
|
|
| 1211 |
+ t.Fatalf("Wrong error %v, must be about missing foo file or directory", err)
|
|
| 1212 |
+ } |
|
| 1213 |
+ } else {
|
|
| 1214 |
+ t.Fatal("Error must not be nil")
|
|
| 1215 |
+ } |
|
| 1216 |
+ logDone("build - add file not found")
|
|
| 1217 |
+} |
| ... | ... |
@@ -414,52 +414,6 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u |
| 414 | 414 |
return image, err |
| 415 | 415 |
} |
| 416 | 416 |
|
| 417 |
-func TestBuildADDFileNotFound(t *testing.T) {
|
|
| 418 |
- eng := NewTestEngine(t) |
|
| 419 |
- defer nuke(mkDaemonFromEngine(eng, t)) |
|
| 420 |
- |
|
| 421 |
- context := testContextTemplate{`
|
|
| 422 |
- from {IMAGE}
|
|
| 423 |
- add foo /usr/local/bar |
|
| 424 |
- `, |
|
| 425 |
- nil, nil} |
|
| 426 |
- |
|
| 427 |
- httpServer, err := mkTestingFileServer(context.remoteFiles) |
|
| 428 |
- if err != nil {
|
|
| 429 |
- t.Fatal(err) |
|
| 430 |
- } |
|
| 431 |
- defer httpServer.Close() |
|
| 432 |
- |
|
| 433 |
- idx := strings.LastIndex(httpServer.URL, ":") |
|
| 434 |
- if idx < 0 {
|
|
| 435 |
- t.Fatalf("could not get port from test http server address %s", httpServer.URL)
|
|
| 436 |
- } |
|
| 437 |
- port := httpServer.URL[idx+1:] |
|
| 438 |
- |
|
| 439 |
- iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
|
|
| 440 |
- if iIP == nil {
|
|
| 441 |
- t.Fatal("Legacy bridgeIP field not set in engine")
|
|
| 442 |
- } |
|
| 443 |
- ip, ok := iIP.(net.IP) |
|
| 444 |
- if !ok {
|
|
| 445 |
- panic("Legacy bridgeIP field in engine does not cast to net.IP")
|
|
| 446 |
- } |
|
| 447 |
- dockerfile := constructDockerfile(context.dockerfile, ip, port) |
|
| 448 |
- |
|
| 449 |
- buildfile := server.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil) |
|
| 450 |
- _, err = buildfile.Build(context.Archive(dockerfile, t)) |
|
| 451 |
- |
|
| 452 |
- if err == nil {
|
|
| 453 |
- t.Log("Error should not be nil")
|
|
| 454 |
- t.Fail() |
|
| 455 |
- } |
|
| 456 |
- |
|
| 457 |
- if err.Error() != "foo: no such file or directory" {
|
|
| 458 |
- t.Logf("Error message is not expected: %s", err.Error())
|
|
| 459 |
- t.Fail() |
|
| 460 |
- } |
|
| 461 |
-} |
|
| 462 |
- |
|
| 463 | 417 |
func TestBuildInheritance(t *testing.T) {
|
| 464 | 418 |
eng := NewTestEngine(t) |
| 465 | 419 |
defer nuke(mkDaemonFromEngine(eng, t)) |