@@ -54,6 +54,123 @@ defmodule Zebra.Workers.Agent.HostedAgentTest do
5454 assert Agent . occupy ( job ) == { :error , error . message }
5555 end
5656 end
57+
58+ test "uses original machine values when migration flag is disabled" do
59+ { :ok , job } =
60+ Support.Factories.Job . create ( :scheduled , % {
61+ machine_type: "e1-standard-2" ,
62+ machine_os_image: "ubuntu2004"
63+ } )
64+
65+ response = % InternalApi.Chmura.OccupyAgentResponse {
66+ agent: % InternalApi.Chmura.Agent { id: @ agent_id }
67+ }
68+
69+ with_mock Stub ,
70+ occupy_agent: fn _ , request , _ ->
71+ assert request . machine . type == "e1-standard-2"
72+ assert request . machine . os_image == "ubuntu2004"
73+ { :ok , response }
74+ end do
75+ assert Agent . occupy ( job ) == { :ok , Agent . construct_agent ( response ) }
76+ end
77+ end
78+
79+ test "remaps e1-standard-2 machines to f1-standard-2 when migration flag is enabled" do
80+ org_id = Support.StubbedProvider . e1_to_f1_org_id ( )
81+
82+ { :ok , job } =
83+ Support.Factories.Job . create ( :scheduled , % {
84+ organization_id: org_id ,
85+ machine_type: "e1-standard-2" ,
86+ machine_os_image: "ubuntu2004"
87+ } )
88+
89+ response = % InternalApi.Chmura.OccupyAgentResponse {
90+ agent: % InternalApi.Chmura.Agent { id: @ agent_id }
91+ }
92+
93+ with_mock Stub ,
94+ occupy_agent: fn _ , request , _ ->
95+ assert request . machine . type == "f1-standard-2"
96+ assert request . machine . os_image == "ubuntu2004"
97+ { :ok , response }
98+ end do
99+ assert Agent . occupy ( job ) == { :ok , Agent . construct_agent ( response ) }
100+ end
101+ end
102+
103+ test "remaps e1-standard-4 machines to f1-standard-2 when migration flag is enabled" do
104+ org_id = Support.StubbedProvider . e1_to_f1_org_id ( )
105+
106+ { :ok , job } =
107+ Support.Factories.Job . create ( :scheduled , % {
108+ organization_id: org_id ,
109+ machine_type: "e1-standard-4" ,
110+ machine_os_image: "ubuntu2004"
111+ } )
112+
113+ response = % InternalApi.Chmura.OccupyAgentResponse {
114+ agent: % InternalApi.Chmura.Agent { id: @ agent_id }
115+ }
116+
117+ with_mock Stub ,
118+ occupy_agent: fn _ , request , _ ->
119+ assert request . machine . type == "f1-standard-2"
120+ assert request . machine . os_image == "ubuntu2004"
121+ { :ok , response }
122+ end do
123+ assert Agent . occupy ( job ) == { :ok , Agent . construct_agent ( response ) }
124+ end
125+ end
126+
127+ test "remaps e1-standard-8 machines to f1-standard-4 when migration flag is enabled" do
128+ org_id = Support.StubbedProvider . e1_to_f1_org_id ( )
129+
130+ { :ok , job } =
131+ Support.Factories.Job . create ( :scheduled , % {
132+ organization_id: org_id ,
133+ machine_type: "e1-standard-8" ,
134+ machine_os_image: "ubuntu2004"
135+ } )
136+
137+ response = % InternalApi.Chmura.OccupyAgentResponse {
138+ agent: % InternalApi.Chmura.Agent { id: @ agent_id }
139+ }
140+
141+ with_mock Stub ,
142+ occupy_agent: fn _ , request , _ ->
143+ assert request . machine . type == "f1-standard-4"
144+ assert request . machine . os_image == "ubuntu2004"
145+ { :ok , response }
146+ end do
147+ assert Agent . occupy ( job ) == { :ok , Agent . construct_agent ( response ) }
148+ end
149+ end
150+
151+ test "does not remap different machine types when migration flag is enabled" do
152+ org_id = Support.StubbedProvider . e1_to_f1_org_id ( )
153+
154+ { :ok , job } =
155+ Support.Factories.Job . create ( :scheduled , % {
156+ organization_id: org_id ,
157+ machine_type: "e2-standard-2" ,
158+ machine_os_image: "ubuntu2004"
159+ } )
160+
161+ response = % InternalApi.Chmura.OccupyAgentResponse {
162+ agent: % InternalApi.Chmura.Agent { id: @ agent_id }
163+ }
164+
165+ with_mock Stub ,
166+ occupy_agent: fn _ , request , _ ->
167+ assert request . machine . type == "e2-standard-2"
168+ assert request . machine . os_image == "ubuntu2004"
169+ { :ok , response }
170+ end do
171+ assert Agent . occupy ( job ) == { :ok , Agent . construct_agent ( response ) }
172+ end
173+ end
57174 end
58175
59176 describe ".release" do
0 commit comments