1# Copyright 2020 Red Hat, Inc 2# All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); you may 5# not use this file except in compliance with the License. You may obtain 6# a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13# License for the specific language governing permissions and limitations 14# under the License. 15 16from glance_store.tests import base 17from glance_store.tests import utils as test_utils 18 19 20class TestFakeData(base.StoreBaseTest): 21 def test_via_read(self): 22 fd = test_utils.FakeData(1024) 23 data = [] 24 for i in range(0, 1025, 256): 25 chunk = fd.read(256) 26 data.append(chunk) 27 if not chunk: 28 break 29 30 self.assertEqual(5, len(data)) 31 # Make sure we got a zero-length final read 32 self.assertEqual(b'', data[-1]) 33 # Make sure we only got 1024 bytes 34 self.assertEqual(1024, len(b''.join(data))) 35 36 def test_via_iter(self): 37 data = b''.join(list(test_utils.FakeData(1024))) 38 self.assertEqual(1024, len(data)) 39