48
48
import org .springframework .util .FileCopyUtils ;
49
49
50
50
import static org .assertj .core .api .Assertions .assertThat ;
51
+ import static org .assertj .core .api .Assertions .entry ;
51
52
52
53
/**
53
54
* Tests for {@link EphemeralBuilder}.
@@ -64,6 +65,8 @@ class EphemeralBuilderTests extends AbstractJsonTests {
64
65
65
66
private Image image ;
66
67
68
+ private ImageReference targetImage ;
69
+
67
70
private BuilderMetadata metadata ;
68
71
69
72
private Map <String , String > env ;
@@ -75,6 +78,7 @@ class EphemeralBuilderTests extends AbstractJsonTests {
75
78
@ BeforeEach
76
79
void setup () throws Exception {
77
80
this .image = Image .of (getContent ("image.json" ));
81
+ this .targetImage = ImageReference .of ("my-image:latest" );
78
82
this .metadata = BuilderMetadata .fromImage (this .image );
79
83
this .env = new HashMap <>();
80
84
this .env .put ("spring" , "boot" );
@@ -83,18 +87,18 @@ void setup() throws Exception {
83
87
84
88
@ Test
85
89
void getNameHasRandomName () throws Exception {
86
- EphemeralBuilder b1 = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , this . env ,
87
- this .buildpacks );
88
- EphemeralBuilder b2 = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , this . env ,
89
- this .buildpacks );
90
+ EphemeralBuilder b1 = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
91
+ this .creator , this . env , this . buildpacks );
92
+ EphemeralBuilder b2 = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
93
+ this .creator , this . env , this . buildpacks );
90
94
assertThat (b1 .getName ().toString ()).startsWith ("pack.local/builder/" ).endsWith (":latest" );
91
95
assertThat (b1 .getName ().toString ()).isNotEqualTo (b2 .getName ().toString ());
92
96
}
93
97
94
98
@ Test
95
99
void getArchiveHasCreatedByConfig () throws Exception {
96
- EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , this . env ,
97
- this .buildpacks );
100
+ EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
101
+ this .creator , this . env , this . buildpacks );
98
102
ImageConfig config = builder .getArchive ().getImageConfig ();
99
103
BuilderMetadata ephemeralMetadata = BuilderMetadata .fromImageConfig (config );
100
104
assertThat (ephemeralMetadata .getCreatedBy ().getName ()).isEqualTo ("Spring Boot" );
@@ -103,16 +107,16 @@ void getArchiveHasCreatedByConfig() throws Exception {
103
107
104
108
@ Test
105
109
void getArchiveHasTag () throws Exception {
106
- EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , this . env ,
107
- this .buildpacks );
110
+ EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
111
+ this .creator , this . env , this . buildpacks );
108
112
ImageReference tag = builder .getArchive ().getTag ();
109
113
assertThat (tag .toString ()).startsWith ("pack.local/builder/" ).endsWith (":latest" );
110
114
}
111
115
112
116
@ Test
113
117
void getArchiveHasFixedCreateDate () throws Exception {
114
- EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , this . env ,
115
- this .buildpacks );
118
+ EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
119
+ this .creator , this . env , this . buildpacks );
116
120
Instant createInstant = builder .getArchive ().getCreateDate ();
117
121
OffsetDateTime createDateTime = OffsetDateTime .ofInstant (createInstant , ZoneId .of ("UTC" ));
118
122
assertThat (createDateTime .getYear ()).isEqualTo (1980 );
@@ -125,22 +129,31 @@ void getArchiveHasFixedCreateDate() throws Exception {
125
129
126
130
@ Test
127
131
void getArchiveContainsEnvLayer () throws Exception {
128
- EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , this . env ,
129
- this .buildpacks );
132
+ EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
133
+ this .creator , this . env , this . buildpacks );
130
134
File directory = unpack (getLayer (builder .getArchive (), 0 ), "env" );
131
135
assertThat (new File (directory , "platform/env/spring" )).usingCharset (StandardCharsets .UTF_8 ).hasContent ("boot" );
132
136
assertThat (new File (directory , "platform/env/empty" )).usingCharset (StandardCharsets .UTF_8 ).hasContent ("" );
133
137
}
134
138
139
+ @ Test
140
+ void getArchiveHasBuilderForLabel () throws Exception {
141
+ EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
142
+ this .creator , this .env , this .buildpacks );
143
+ ImageConfig config = builder .getArchive ().getImageConfig ();
144
+ assertThat (config .getLabels ())
145
+ .contains (entry (EphemeralBuilder .BUILDER_FOR_LABEL_NAME , this .targetImage .toString ()));
146
+ }
147
+
135
148
@ Test
136
149
void getArchiveContainsBuildpackLayers () throws Exception {
137
150
List <Buildpack > buildpackList = new ArrayList <>();
138
151
buildpackList .add (new TestBuildpack ("example/buildpack1" , "0.0.1" ));
139
152
buildpackList .add (new TestBuildpack ("example/buildpack2" , "0.0.2" ));
140
153
buildpackList .add (new TestBuildpack ("example/buildpack3" , "0.0.3" ));
141
154
this .buildpacks = Buildpacks .of (buildpackList );
142
- EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .metadata , this .creator , null ,
143
- this .buildpacks );
155
+ EphemeralBuilder builder = new EphemeralBuilder (this .owner , this .image , this .targetImage , this .metadata ,
156
+ this .creator , null , this . buildpacks );
144
157
assertBuildpackLayerContent (builder , 0 , "/cnb/buildpacks/example_buildpack1/0.0.1/buildpack.toml" );
145
158
assertBuildpackLayerContent (builder , 1 , "/cnb/buildpacks/example_buildpack2/0.0.2/buildpack.toml" );
146
159
assertBuildpackLayerContent (builder , 2 , "/cnb/buildpacks/example_buildpack3/0.0.3/buildpack.toml" );
0 commit comments