-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing test for rule- lock states
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
test/gateway/rule/rule-gateway-list-rule-replica-lock-states.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { RuleReplicaLockStateDTO } from "@/lib/core/dto/rule-dto"; | ||
import RuleGatewayOutputPort from "@/lib/core/port/secondary/rule-gateway-output-port"; | ||
import appContainer from "@/lib/infrastructure/ioc/container-config"; | ||
import GATEWAYS from "@/lib/infrastructure/ioc/ioc-symbols-gateway"; | ||
import { Readable } from "stream"; | ||
import MockRucioServerFactory, { MockEndpoint } from "test/fixtures/rucio-server"; | ||
import { collectStreamedData } from "test/fixtures/stream-test-utils"; | ||
|
||
|
||
describe("RuleGateway", () => { | ||
beforeEach(() => { | ||
fetchMock.doMock(); | ||
const ruleReplicaLockStateStream = Readable.from([ | ||
JSON.stringify({ | ||
"scope": "test", | ||
"name": "file1", | ||
"rse_id": "e815ec46bfa2427cac191cc36ac94527", | ||
"rse": "XRD3", | ||
"state": "REPLICATING", | ||
"rule_id": "0dcdc93fab714f8b84bad116c409483b" | ||
}), | ||
JSON.stringify({ | ||
"scope": "test", | ||
"name": "file2", | ||
"rse_id": "e815ec46bfa2427cac191cc36ac94527", | ||
"rse": "XRD3", | ||
"state": "REPLICATING", | ||
"rule_id": "0dcdc93fab714f8b84bad116c409483b" | ||
}), | ||
JSON.stringify({ | ||
"scope": "test", | ||
"name": "file3", | ||
"rse_id": "e815ec46bfa2427cac191cc36ac94527", | ||
"rse": "XRD3", | ||
"state": "REPLICATING", | ||
"rule_id": "0dcdc93fab714f8b84bad116c409483b" | ||
}), | ||
JSON.stringify({ | ||
"scope": "test", | ||
"name": "file4", | ||
"rse_id": "e815ec46bfa2427cac191cc36ac94527", | ||
"rse": "XRD3", | ||
"state": "REPLICATING", | ||
"rule_id": "0dcdc93fab714f8b84bad116c409483b" | ||
}) | ||
]) | ||
|
||
const listRuleReplicaLockStatesEndpoint: MockEndpoint = { | ||
url: `${MockRucioServerFactory.RUCIO_HOST}/rules/0dcdc93fab714f8b84bad116c409483b/locks`, | ||
method: 'GET', | ||
includes: 'locks', | ||
response: { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/x-json-stream', | ||
}, | ||
body: ruleReplicaLockStateStream | ||
} | ||
} | ||
|
||
MockRucioServerFactory.createMockRucioServer(true, [listRuleReplicaLockStatesEndpoint]); | ||
}); | ||
|
||
afterEach(() => { | ||
fetchMock.dontMock(); | ||
}); | ||
|
||
it("Should fetch a list of rule replica lock states", async () => { | ||
const ruleGateway: RuleGatewayOutputPort = appContainer.get<RuleGatewayOutputPort>(GATEWAYS.RULE); | ||
const listRuleReplicaLockStatesDTO = await ruleGateway.listRuleReplicaLockStates(MockRucioServerFactory.VALID_RUCIO_TOKEN, '0dcdc93fab714f8b84bad116c409483b'); | ||
expect(listRuleReplicaLockStatesDTO.status).toEqual('success'); | ||
|
||
const ruleReplicaLockStateStream = listRuleReplicaLockStatesDTO.stream; | ||
if(ruleReplicaLockStateStream == null || ruleReplicaLockStateStream == undefined) { | ||
fail('Rule replica lock state stream is null or undefined'); | ||
} | ||
|
||
const recievedData = await collectStreamedData<RuleReplicaLockStateDTO>(ruleReplicaLockStateStream); | ||
expect(recievedData.length).toEqual(4); | ||
expect(recievedData[0].rse).toEqual('XRD3'); | ||
expect(recievedData[0].name).toEqual('file1'); | ||
}); | ||
}); |