@@ -78,6 +78,20 @@ public void entrypointAndWorkingDirAreStampedAndCmdIsCleared() throws IOExceptio
7878 "a base Cmd left in place would run jshell instead of the launcher" );
7979 }
8080
81+ @ Test
82+ public void notCallingWithCmdLeavesTheBaseCmdInPlace () throws IOException {
83+ ImageConfigOverrides overrides = new ImageConfigOverrides ()
84+ .withEntrypoint (Arrays .asList ("/opt/spisor/launcher/bin/launcher" ))
85+ .withWorkingDir ("/var/lib/spisor" );
86+
87+ JsonObject config = GSON .fromJson (
88+ ImageAssembler .append (fixture ("base-config.json" ), fixture ("base-manifest.json" ),
89+ layer (), overrides ).configJson (),
90+ JsonObject .class ).getAsJsonObject ("config" );
91+
92+ assertEquals ("jshell" , config .getAsJsonArray ("Cmd" ).get (0 ).getAsString ());
93+ }
94+
8195 @ Test
8296 public void theBaseEnvironmentSurvives () throws IOException {
8397 JsonObject config = GSON .fromJson (assemble ().configJson (), JsonObject .class )
@@ -141,15 +155,46 @@ public void aDockerSchema2BaseKeepsDockerMediaTypesThroughout() throws IOExcepti
141155 manifest .getAsJsonArray ("layers" ).get (2 ).getAsJsonObject ().get ("mediaType" ).getAsString ());
142156 }
143157
158+ @ Test
159+ public void aBaseConfigWithNoHistoryArrayGetsOneCreated () throws IOException {
160+ String baseConfigWithoutHistory = "{\" architecture\" :\" amd64\" ,\" os\" :\" linux\" ,"
161+ + "\" config\" :{\" Env\" :[],\" Cmd\" :[\" jshell\" ]},"
162+ + "\" rootfs\" :{\" type\" :\" layers\" ,\" diff_ids\" :["
163+ + "\" sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" ,"
164+ + "\" sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\" ]}}" ;
165+
166+ JsonObject config = GSON .fromJson (
167+ ImageAssembler .append (baseConfigWithoutHistory , fixture ("base-manifest.json" ),
168+ layer (), overrides ()).configJson (),
169+ JsonObject .class );
170+
171+ assertEquals (1 , config .getAsJsonArray ("history" ).size ());
172+ }
173+
174+ @ Test
175+ public void aBaseConfigWithNoInnerConfigObjectGetsOneCreated () throws IOException {
176+ String baseConfigWithoutInnerConfig = "{\" architecture\" :\" amd64\" ,\" os\" :\" linux\" ,"
177+ + "\" rootfs\" :{\" type\" :\" layers\" ,\" diff_ids\" :["
178+ + "\" sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" ,"
179+ + "\" sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\" ]}}" ;
180+
181+ JsonObject config = GSON .fromJson (
182+ ImageAssembler .append (baseConfigWithoutInnerConfig , fixture ("base-manifest.json" ),
183+ layer (), overrides ()).configJson (),
184+ JsonObject .class ).getAsJsonObject ("config" );
185+
186+ assertEquals ("/opt/spisor/launcher/bin/launcher" , config .getAsJsonArray ("Entrypoint" ).get (0 ).getAsString ());
187+ }
188+
144189 private static String fixture (String name ) throws IOException {
145- InputStream in = ImageAssemblerTest .class .getResourceAsStream ("/registry/" + name );
146190 ByteArrayOutputStream out = new ByteArrayOutputStream ();
147- byte [] buffer = new byte [8192 ];
148- int read ;
149- while ((read = in .read (buffer )) != -1 ) {
150- out .write (buffer , 0 , read );
191+ try (InputStream in = ImageAssemblerTest .class .getResourceAsStream ("/registry/" + name )) {
192+ byte [] buffer = new byte [8192 ];
193+ int read ;
194+ while ((read = in .read (buffer )) != -1 ) {
195+ out .write (buffer , 0 , read );
196+ }
151197 }
152- in .close ();
153198 return new String (out .toByteArray (), StandardCharsets .UTF_8 );
154199 }
155200}
0 commit comments