Coverage for tests/integration/__init__.py: 100%

46 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:55 -0600

1"""Integration Test Setup""" 

2 

3import logging 

4import pytest 

5from es_testbed import PlanBuilder, TestBed 

6 

7 

8class TestAny: 

9 """ 

10 Test Any index or data_stream 

11 

12 Set this up by setting class variables, as below. 

13 """ 

14 

15 sstier = 'hot' 

16 kind = 'data_stream' 

17 roll = False 

18 repo_test = False 

19 ilm = { 

20 'enabled': False, 

21 'tiers': ['hot', 'delete'], 

22 'forcemerge': False, 

23 'max_num_segments': 1, 

24 } 

25 logger = logging.getLogger(__name__) 

26 

27 @pytest.fixture(scope="class") 

28 def tb(self, client, settings, skip_no_repo, skip_localhost): 

29 """TestBed setup/teardown""" 

30 skip_no_repo(self.repo_test) 

31 skip_localhost( 

32 bool( 

33 self.sstier in ['frozen'] 

34 and self.ilm['enabled'] is True 

35 and ( 

36 self.kind == 'data_stream' 

37 or (self.kind == 'indices' and self.roll is True) 

38 ) 

39 ) 

40 ) 

41 skip_localhost(False) 

42 cfg = settings( 

43 plan_type=self.kind, 

44 rollover_alias=self.roll, 

45 ilm=self.ilm, 

46 sstier=self.sstier, 

47 ) 

48 theplan = PlanBuilder(settings=cfg).plan 

49 teebee = TestBed(client, plan=theplan) 

50 teebee.setup() 

51 yield teebee 

52 teebee.teardown() 

53 

54 def test_entity_count(self, entity_count, entitymgr, tb): 

55 """Count the number of entities (index or data_stream)""" 

56 assert len(entitymgr(tb).entity_list) == entity_count(self.kind) 

57 

58 def test_name(self, actual_rollover, rollovername, tb): 

59 """ 

60 Verify the name of a rollover alias or data_stream 

61 

62 Will still return True if not a rollover or data_stream enabled test 

63 """ 

64 assert actual_rollover(tb) == rollovername(tb.plan) 

65 

66 def test_first_index(self, actual_index, first, index_name, tb): 

67 """Assert that the first index matches the expected name""" 

68 expected = index_name(which=first, plan=tb.plan, tier=self.sstier) 

69 actual = actual_index(tb, first) 

70 assert actual == expected 

71 

72 def test_last_index(self, actual_index, index_name, last, tb): 

73 """Assert that the last index matches the expected name""" 

74 expected = index_name(which=last, plan=tb.plan, tier=self.sstier) 

75 actual = actual_index(tb, last) 

76 assert actual == expected 

77 

78 def test_write_index(self, tb, actual_write_index, write_index_name): 

79 """ 

80 Test that the write index or current data_stream target is correct 

81 

82 Will still return True if not a rollover or data_stream enabled test 

83 """ 

84 expected = write_index_name(plan=tb.plan, tier=self.sstier) 

85 self.logger.debug('PLAN: %s', tb.plan) 

86 self.logger.debug('expected: %s', expected) 

87 actual = actual_write_index(tb) 

88 self.logger.debug('actual: %s', actual) 

89 assert actual == expected 

90 

91 def test_index_template(self, tb, components, get_template, template): 

92 """Assert that the index template and component templates are correct""" 

93 assert tb.componentmgr.entity_list == components 

94 assert tb.templatemgr.last == template 

95 result = get_template(tb.client) 

96 assert len(result) == 1 

97 assert result[0]['index_template']['composed_of'] == components