Skip to content

Commit fc6bccb

Browse files
authored
Merge pull request #1570 from buildpacks/jab/fix-tests-0-15
Fixing detector tests
2 parents b01c4e5 + aab8470 commit fc6bccb

File tree

8 files changed

+43
-9
lines changed

8 files changed

+43
-9
lines changed

acceptance/detector_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ fail: fail_detect_buildpack@some_version`
449449
detectImage,
450450
h.WithFlags("--user", userID,
451451
"--env", "CNB_ORDER_PATH=/cnb/orders/middle_order.toml",
452-
"--env", "CNB_SYSTEM_PATH=/cnb/system.toml",
452+
"--env", "CNB_SYSTEM_PATH=/cnb/test-data/system.toml",
453453
"--env", "CNB_PLATFORM_API="+platformAPI,
454454
),
455455
h.WithArgs("-log-level=debug"),
@@ -475,13 +475,16 @@ fail: fail_detect_buildpack@some_version`
475475
h.AssertEq(t, group.Group[2].Version, "simple_buildpack_version")
476476

477477
// check output contains all buildpacks
478-
h.AssertStringContains(t, output, "always_detect_buildpack always_detect_buildpack_version")
479-
h.AssertStringContains(t, output, "buildpack_for_ext buildpack_for_ext_version")
480-
h.AssertStringContains(t, output, "simple_buildpack simple_buildpack_version")
478+
h.AssertStringContains(t, output, "always_detect_buildpack")
479+
h.AssertStringContains(t, output, "always_detect_buildpack_version")
480+
h.AssertStringContains(t, output, "buildpack_for_ext")
481+
h.AssertStringContains(t, output, "buildpack_for_ext_version")
482+
h.AssertStringContains(t, output, "simple_buildpack")
483+
h.AssertStringContains(t, output, "simple_buildpack_version")
481484

482485
// check debug logs show system buildpack merging
483-
h.AssertStringContains(t, output, "Prepending 1 system buildpack(s) to order")
484-
h.AssertStringContains(t, output, "Appending 1 system buildpack(s) to order")
486+
h.AssertStringContains(t, output, "Prepending 1 system buildpack(s) to group")
487+
h.AssertStringContains(t, output, "Appending 1 system buildpack(s) to group")
485488
})
486489
})
487490
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
## always detect
4+
5+
platform_path=$1
6+
plan_path=$2
7+
8+
echo "ENV"
9+
env
10+
11+
echo "platform_path: $platform_path"
12+
echo "app_dir: $(pwd)"
13+
14+
cat >> "${plan_path}" <<EOL
15+
[[provides]]
16+
name = "some_requirement"
17+
EOL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
api = "0.10"
2+
3+
[buildpack]
4+
id = "always_detect_buildpack"
5+
version = "always_detect_buildpack_version"
6+
name = "Always Detect Buildpack"

acceptance/testdata/detector/container/cnb/system.toml renamed to acceptance/testdata/detector/container/cnb/test-data/system.toml

File renamed without changes.

phase/detector_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
5555
configHandler,
5656
dirStore,
5757
)
58+
59+
// Mock ReadSystem for Platform API >= 0.15 (returns empty by default)
60+
if api.Platform.Latest().AtLeast("0.15") {
61+
configHandler.EXPECT().ReadSystem(gomock.Any(), gomock.Any()).Return(files.System{}, nil).AnyTimes()
62+
}
5863
})
5964

6065
it.After(func() {
@@ -99,6 +104,8 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
99104

100105
when("Platform API >= 0.15", func() {
101106
it("reads and merges system buildpacks", func() {
107+
configHandler = testmock.NewMockConfigHandler(mockController)
108+
102109
detectorFactory015 := phase.NewHermeticFactory(
103110
api.MustParse("0.15"),
104111
apiVerifier,
@@ -121,6 +128,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) {
121128
},
122129
},
123130
}
131+
configHandler.EXPECT().ReadAnalyzed("some-analyzed-path", gomock.Any()).Return(files.Analyzed{}, nil)
124132
configHandler.EXPECT().ReadOrder("some-order-path").Return(order, nil, nil)
125133
configHandler.EXPECT().ReadSystem("some-system-path", gomock.Any()).Return(system, nil)
126134

priv/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func DockerClient() (*client.Client, error) {
3333
}
3434
opts = append(opts, opt)
3535
}
36-
return client.NewClientWithOpts(opts...)
36+
return client.New(opts...)
3737
}
3838

3939
type unclosableConn struct {

testhelpers/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
func DockerCli(t *testing.T) dockercli.APIClient {
3030
dockerCliOnce.Do(func() {
3131
var dockerCliErr error
32-
dockerCliVal, dockerCliErr = dockercli.NewClientWithOpts(dockercli.FromEnv, dockercli.WithVersion("1.38"))
32+
dockerCliVal, dockerCliErr = dockercli.New(dockercli.FromEnv)
3333
AssertNil(t, dockerCliErr)
3434
})
3535
return dockerCliVal

tools/image/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func main() {
6666

6767
var img imgutil.Image
6868
if useDaemon {
69-
dockerClient, err := dockercli.NewClientWithOpts(dockercli.FromEnv, dockercli.WithVersion("1.38"))
69+
dockerClient, err := dockercli.New(dockercli.FromEnv)
7070
if err != nil {
7171
log.Fatal("Failed to initialize docker client:", err)
7272
}

0 commit comments

Comments
 (0)