allow(kubeclient).toreceive(:get_cilium_network_policy).with(resource_name,environment.deployment_namespace).and_raise(Kubeclient::ResourceNotFoundError.new(404,'policy not found',{}))
end
let(:policy)do
{
creation_timestamp: nil,
environment_ids: [],
is_autodevops: false,
is_enabled: false,
name: "drop-outbound",
namespace: nil
}
end
context'and has name reserved for predefined policy'do
let(:resource_name){'drop-outbound'}
it'returns success response with predefined policy'do
expect(subject).tobe_success
expect(subject.payload.as_json).toinclude(policy)
end
end
context'and has name different from any predefined policy'do
let(:resource_name){'not-predefined-policy'}
it'returns success response with predefined policy'do
expect(subject).tobe_error
expect(subject.http_status).toeq(:bad_request)
expect(subject.message).toeq('Kubernetes error: policy not found')
end
end
end
end
context'with invalid policy kind'do
...
...
@@ -57,7 +94,7 @@ RSpec.describe NetworkPolicies::FindResourceService do
it'returns error response'do
expect(subject).tobe_error
expect(subject.http_status).toeq(:bad_request)
expect(subject.message).not_tobe_nil
expect(subject.message).toeq('Invalid or unsupported policy kind')
end
end
...
...
@@ -67,7 +104,7 @@ RSpec.describe NetworkPolicies::FindResourceService do
it'returns error response'do
expect(subject).tobe_error
expect(subject.http_status).toeq(:bad_request)
expect(subject.message).not_tobe_nil
expect(subject.message).toeq('Environment does not have deployment platform')