@@ -85,4 +85,76 @@ void testAddWithAdvancedOptions(MockServerClient mock) throws IOException {
8585 assertEquals (0 , out .exitCode );
8686 }
8787
88+ @ Test
89+ void testAddWithInstanceTemplates (MockServerClient mock ) throws IOException {
90+
91+ mock .reset ();
92+
93+ mock .when (
94+ request ().withMethod ("GET" ).withPath ("/credentials" ).withQueryStringParameter ("platformId" , "google-batch" ), exactly (1 )
95+ ).respond (
96+ response ().withStatusCode (200 ).withBody ("{\" credentials\" :[{\" id\" :\" 6XfOhoztUq6de3Dw3X9LSb\" ,\" name\" :\" google\" ,\" description\" :null,\" discriminator\" :\" google\" ,\" baseUrl\" :null,\" category\" :null,\" deleted\" :null,\" lastUsed\" :\" 2021-09-08T18:20:46Z\" ,\" dateCreated\" :\" 2021-09-08T12:57:04Z\" ,\" lastUpdated\" :\" 2021-09-08T12:57:04Z\" }]}" ).withContentType (MediaType .APPLICATION_JSON )
97+ );
98+
99+ mock .when (
100+ request ().withMethod ("POST" ).withPath ("/compute-envs" )
101+ .withBody (JsonBody .json ("{\" computeEnv\" :{\" credentialsId\" :\" 6XfOhoztUq6de3Dw3X9LSb\" ,\" name\" :\" google\" ,\" platform\" :\" google-batch\" ,\" config\" :{\" location\" :\" europe\" ,\" workDir\" :\" gs://workdir\" ,\" fusion2Enabled\" :false,\" waveEnabled\" :false,\" headJobInstanceTemplate\" :\" projects/my-project/global/instanceTemplates/head-template\" ,\" computeJobsInstanceTemplate\" :\" projects/my-project/global/instanceTemplates/compute-template\" }}}" )), exactly (1 )
102+ ).respond (
103+ response ().withStatusCode (200 ).withBody ("{\" computeEnvId\" :\" isnEDBLvHDAIteOEF44ow\" }" ).withContentType (MediaType .APPLICATION_JSON )
104+ );
105+
106+ ExecOut out = exec (mock , "compute-envs" , "add" , "google-batch" , "-n" , "google" , "--work-dir" , "gs://workdir" , "-l" , "europe" , "--head-job-template" , "projects/my-project/global/instanceTemplates/head-template" , "--compute-job-template" , "projects/my-project/global/instanceTemplates/compute-template" );
107+ assertEquals ("" , out .stdErr );
108+ assertEquals (new ComputeEnvAdded ("google-batch" , "isnEDBLvHDAIteOEF44ow" , "google" , null , USER_WORKSPACE_NAME ).toString (), out .stdOut );
109+ assertEquals (0 , out .exitCode );
110+ }
111+
112+ @ Test
113+ void testAddWithOnlyHeadJobTemplate (MockServerClient mock ) throws IOException {
114+
115+ mock .reset ();
116+
117+ mock .when (
118+ request ().withMethod ("GET" ).withPath ("/credentials" ).withQueryStringParameter ("platformId" , "google-batch" ), exactly (1 )
119+ ).respond (
120+ response ().withStatusCode (200 ).withBody ("{\" credentials\" :[{\" id\" :\" 6XfOhoztUq6de3Dw3X9LSb\" ,\" name\" :\" google\" ,\" description\" :null,\" discriminator\" :\" google\" ,\" baseUrl\" :null,\" category\" :null,\" deleted\" :null,\" lastUsed\" :\" 2021-09-08T18:20:46Z\" ,\" dateCreated\" :\" 2021-09-08T12:57:04Z\" ,\" lastUpdated\" :\" 2021-09-08T12:57:04Z\" }]}" ).withContentType (MediaType .APPLICATION_JSON )
121+ );
122+
123+ mock .when (
124+ request ().withMethod ("POST" ).withPath ("/compute-envs" )
125+ .withBody (JsonBody .json ("{\" computeEnv\" :{\" credentialsId\" :\" 6XfOhoztUq6de3Dw3X9LSb\" ,\" name\" :\" google\" ,\" platform\" :\" google-batch\" ,\" config\" :{\" location\" :\" europe\" ,\" workDir\" :\" gs://workdir\" ,\" fusion2Enabled\" :false,\" waveEnabled\" :false,\" headJobInstanceTemplate\" :\" projects/my-project/global/instanceTemplates/head-template\" }}}" )), exactly (1 )
126+ ).respond (
127+ response ().withStatusCode (200 ).withBody ("{\" computeEnvId\" :\" isnEDBLvHDAIteOEF44ow\" }" ).withContentType (MediaType .APPLICATION_JSON )
128+ );
129+
130+ ExecOut out = exec (mock , "compute-envs" , "add" , "google-batch" , "-n" , "google" , "--work-dir" , "gs://workdir" , "-l" , "europe" , "--head-job-template" , "projects/my-project/global/instanceTemplates/head-template" );
131+ assertEquals ("" , out .stdErr );
132+ assertEquals (new ComputeEnvAdded ("google-batch" , "isnEDBLvHDAIteOEF44ow" , "google" , null , USER_WORKSPACE_NAME ).toString (), out .stdOut );
133+ assertEquals (0 , out .exitCode );
134+ }
135+
136+ @ Test
137+ void testAddWithOnlyComputeJobTemplate (MockServerClient mock ) throws IOException {
138+
139+ mock .reset ();
140+
141+ mock .when (
142+ request ().withMethod ("GET" ).withPath ("/credentials" ).withQueryStringParameter ("platformId" , "google-batch" ), exactly (1 )
143+ ).respond (
144+ response ().withStatusCode (200 ).withBody ("{\" credentials\" :[{\" id\" :\" 6XfOhoztUq6de3Dw3X9LSb\" ,\" name\" :\" google\" ,\" description\" :null,\" discriminator\" :\" google\" ,\" baseUrl\" :null,\" category\" :null,\" deleted\" :null,\" lastUsed\" :\" 2021-09-08T18:20:46Z\" ,\" dateCreated\" :\" 2021-09-08T12:57:04Z\" ,\" lastUpdated\" :\" 2021-09-08T12:57:04Z\" }]}" ).withContentType (MediaType .APPLICATION_JSON )
145+ );
146+
147+ mock .when (
148+ request ().withMethod ("POST" ).withPath ("/compute-envs" )
149+ .withBody (JsonBody .json ("{\" computeEnv\" :{\" credentialsId\" :\" 6XfOhoztUq6de3Dw3X9LSb\" ,\" name\" :\" google\" ,\" platform\" :\" google-batch\" ,\" config\" :{\" location\" :\" europe\" ,\" workDir\" :\" gs://workdir\" ,\" fusion2Enabled\" :false,\" waveEnabled\" :false,\" computeJobsInstanceTemplate\" :\" projects/my-project/global/instanceTemplates/compute-template\" }}}" )), exactly (1 )
150+ ).respond (
151+ response ().withStatusCode (200 ).withBody ("{\" computeEnvId\" :\" isnEDBLvHDAIteOEF44ow\" }" ).withContentType (MediaType .APPLICATION_JSON )
152+ );
153+
154+ ExecOut out = exec (mock , "compute-envs" , "add" , "google-batch" , "-n" , "google" , "--work-dir" , "gs://workdir" , "-l" , "europe" , "--compute-job-template" , "projects/my-project/global/instanceTemplates/compute-template" );
155+ assertEquals ("" , out .stdErr );
156+ assertEquals (new ComputeEnvAdded ("google-batch" , "isnEDBLvHDAIteOEF44ow" , "google" , null , USER_WORKSPACE_NAME ).toString (), out .stdOut );
157+ assertEquals (0 , out .exitCode );
158+ }
159+
88160}
0 commit comments