45
45
import static org .mockito .MockitoAnnotations .initMocks ;
46
46
47
47
public class ShouldAssignWorkRequestExecutorTest extends BaseTest {
48
- private final String environment = "production" ;
49
48
@ Mock
50
49
KubernetesClientFactory factory ;
51
50
private AgentInstances <KubernetesInstance > agentInstances ;
@@ -57,6 +56,7 @@ public class ShouldAssignWorkRequestExecutorTest extends BaseTest {
57
56
private MixedOperation <Pod , PodList , DoneablePod , PodResource <Pod , DoneablePod >> mockedOperation ;
58
57
@ Mock
59
58
private NonNamespaceOperation <Pod , PodList , DoneablePod , PodResource <Pod , DoneablePod >> mockedNamespaceOperation ;
59
+ private String environment = "QA" ;
60
60
61
61
@ Before
62
62
public void setUp () throws Exception {
@@ -69,28 +69,23 @@ public void setUp() throws Exception {
69
69
agentInstances = new KubernetesAgentInstances (factory );
70
70
properties .put ("foo" , "bar" );
71
71
properties .put ("Image" , "gocdcontrib/ubuntu-docker-elastic-agent" );
72
- instance = agentInstances .create (new CreateAgentRequest (UUID .randomUUID ().toString (), properties , environment , new JobIdentifier (1L )), createSettings (), null );
72
+ instance = agentInstances .create (new CreateAgentRequest (UUID .randomUUID ().toString (), properties , environment , new JobIdentifier (100L )), createSettings (), null );
73
73
}
74
74
75
75
@ Test
76
- public void shouldAssignWorkToContainerWithMatchingEnvironmentNameAndProperties () throws Exception {
77
- ShouldAssignWorkRequest request = new ShouldAssignWorkRequest (new Agent (instance .name (), null , null , null ), environment , properties );
76
+ public void shouldAssignWorkWhenJobIdMatchesPodId () throws Exception {
77
+ JobIdentifier jobIdentifier = new JobIdentifier ("test-pipeline" , 1L , "Test Pipeline" , "test-stage" , "1" , "test-job" , 100L );
78
+ ShouldAssignWorkRequest request = new ShouldAssignWorkRequest (new Agent (instance .name (), null , null , null ), environment , properties , jobIdentifier );
78
79
GoPluginApiResponse response = new ShouldAssignWorkRequestExecutor (request , agentInstances ).execute ();
79
80
assertThat (response .responseCode (), is (200 ));
80
81
assertThat (response .responseBody (), is ("true" ));
81
82
}
82
83
83
84
@ Test
84
- public void shouldNotAssignWorkToContainerWithDifferentEnvironmentName () throws Exception {
85
- ShouldAssignWorkRequest request = new ShouldAssignWorkRequest (new Agent (instance .name (), null , null , null ), "FooEnv" , properties );
86
- GoPluginApiResponse response = new ShouldAssignWorkRequestExecutor (request , agentInstances ).execute ();
87
- assertThat (response .responseCode (), is (200 ));
88
- assertThat (response .responseBody (), is ("false" ));
89
- }
90
-
91
- @ Test
92
- public void shouldNotAssignWorkToContainerWithDifferentProperties () throws Exception {
93
- ShouldAssignWorkRequest request = new ShouldAssignWorkRequest (new Agent (instance .name (), null , null , null ), environment , null );
85
+ public void shouldNotAssignWorkWhenJobIdDiffersFromPodId () throws Exception {
86
+ long mismatchingJobId = 200L ;
87
+ JobIdentifier jobIdentifier = new JobIdentifier ("test-pipeline" , 1L , "Test Pipeline" , "test-stage" , "1" , "test-job" , mismatchingJobId );
88
+ ShouldAssignWorkRequest request = new ShouldAssignWorkRequest (new Agent (instance .name (), null , null , null ), "FooEnv" , properties , jobIdentifier );
94
89
GoPluginApiResponse response = new ShouldAssignWorkRequestExecutor (request , agentInstances ).execute ();
95
90
assertThat (response .responseCode (), is (200 ));
96
91
assertThat (response .responseBody (), is ("false" ));
0 commit comments