| 
									
										
										
										
											2016-07-22 17:29:18 -05:00
										 |  |  | # verifies: | 
					
						
							|  |  |  | #   1. GoCD agent starts | 
					
						
							|  |  |  | #   2. GoCD agent responds | 
					
						
							|  |  |  | #   3. GoCD agent is available on GoCD server using GoCD API | 
					
						
							|  |  |  | #     3.1. https://api.go.cd/current/#get-all-agents | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 10:10:13 -05:00
										 |  |  | let | 
					
						
							|  |  |  |   serverUrl = "localhost:8153/go/api/agents"; | 
					
						
							| 
									
										
										
										
											2016-08-10 15:47:29 -04:00
										 |  |  |   header = "Accept: application/vnd.go.cd.v2+json"; | 
					
						
							| 
									
										
										
										
											2016-08-10 10:10:13 -05:00
										 |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-24 22:48:59 +01:00
										 |  |  | import ./make-test-python.nix ({ pkgs, ...} : { | 
					
						
							| 
									
										
										
										
											2016-07-22 17:29:18 -05:00
										 |  |  |   name = "gocd-agent"; | 
					
						
							|  |  |  |   meta = with pkgs.stdenv.lib.maintainers; { | 
					
						
							| 
									
										
										
										
											2016-08-10 10:10:13 -05:00
										 |  |  |     maintainers = [ grahamc swarren83 ]; | 
					
						
							| 
									
										
										
										
											2019-12-04 00:35:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # gocd agent needs to register with the autoregister key created on first server startup, | 
					
						
							|  |  |  |     # but NixOS module doesn't seem to allow to pass during runtime currently | 
					
						
							|  |  |  |     broken = true; | 
					
						
							| 
									
										
										
										
											2016-07-22 17:29:18 -05:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 15:47:29 -04:00
										 |  |  |   nodes = { | 
					
						
							| 
									
										
										
										
											2019-11-24 22:48:59 +01:00
										 |  |  |     agent = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |       { ... }: | 
					
						
							| 
									
										
										
										
											2016-08-10 15:47:29 -04:00
										 |  |  |       { | 
					
						
							| 
									
										
										
										
											2016-08-10 16:21:35 -04:00
										 |  |  |         virtualisation.memorySize = 2046; | 
					
						
							| 
									
										
										
										
											2016-08-10 15:47:29 -04:00
										 |  |  |         services.gocd-agent = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         services.gocd-server = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2016-07-22 17:29:18 -05:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2016-08-10 15:47:29 -04:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-07-22 17:29:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   testScript = ''
 | 
					
						
							| 
									
										
										
										
											2019-11-24 22:48:59 +01:00
										 |  |  |     start_all() | 
					
						
							|  |  |  |     agent.wait_for_unit("gocd-server") | 
					
						
							|  |  |  |     agent.wait_for_open_port("8153") | 
					
						
							|  |  |  |     agent.wait_for_unit("gocd-agent") | 
					
						
							|  |  |  |     agent.wait_until_succeeds( | 
					
						
							|  |  |  |         "curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].uuid" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     agent.succeed( | 
					
						
							|  |  |  |         "curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].agent_state | grep -q Idle" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-07-22 17:29:18 -05:00
										 |  |  |   '';
 | 
					
						
							|  |  |  | }) |