Skip to content

Commit

Permalink
Improve tag mapping specs
Browse files Browse the repository at this point in the history
- Use factory for more accurate test.
  Previous test didn't set read_only nor used 'kubernetes:' prefix,
  will fail with upcoming retagging implementation.

- Test that we don't remove user-assigned tags.
  • Loading branch information
cben committed Nov 19, 2017
1 parent e3a711a commit 54595b6
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

# Smoke test the use of ContainerLabelTagMapping during refresh.
before :each do
@name_category = FactoryGirl.create(:classification, :name => 'name', :description => 'Name')
@label_tag_mapping = FactoryGirl.create(
:container_label_tag_mapping,
:label_name => 'name', :tag => @name_category.tag
)
mapping = FactoryGirl.create(:tag_mapping_with_category, :label_name => 'name')
@name_category = mapping.tag.category

@user_tag = FactoryGirl.create(:classification_cost_center_with_tags).entries.first.tag
end

def full_refresh_test
expected_extra_tags = []

3.times do # Run three times to verify that second & third runs with existing data do not change anything
VCR.use_cassette(described_class.name.underscore) do # , :record => :new_episodes) do
EmsRefresh.refresh(@ems)
Expand All @@ -44,15 +45,20 @@ def full_refresh_test
assert_authentication
assert_table_counts
assert_specific_container
assert_specific_container_group
assert_specific_container_group(:expected_extra_tags => expected_extra_tags)
assert_specific_container_node
assert_specific_container_service
assert_specific_container_replicator
assert_specific_container_replicator(:expected_extra_tags => expected_extra_tags)
assert_specific_container_project
assert_specific_container_quota
assert_specific_container_limit
assert_specific_container_image_and_registry
# Volumes, PVs, and PVCs are tested in _before_deletions VCR.

# Once records exist, simulate user assigning tags by Edit Tags, to test later refreshes don't remove them.
@replicator.reload.tags |= [@user_tag]
@containergroup.reload.tags |= [@user_tag]
expected_extra_tags = [@user_tag]
end
end

Expand Down Expand Up @@ -138,7 +144,7 @@ def assert_specific_container
)
end

def assert_specific_container_group
def assert_specific_container_group(expected_extra_tags: [])
@containergroup = ContainerGroup.find_by(:name => "monitoring-heapster-controller-4j5zu")
expect(@containergroup).to have_attributes(
# :ems_ref => "49984e80-e1b7-11e4-b7dc-001a4a5f4a02",
Expand All @@ -152,7 +158,8 @@ def assert_specific_container_group
)
if check_tag_mapping
expect(@containergroup.tags).to contain_exactly(
tag_in_category_with_description(@name_category, "heapster")
tag_in_category_with_description(@name_category, "heapster"),
*expected_extra_tags
)
end

Expand Down Expand Up @@ -279,7 +286,7 @@ def assert_specific_container_service
expect(@containersrv.container_nodes.count).to eq(0)
end

def assert_specific_container_replicator
def assert_specific_container_replicator(expected_extra_tags: [])
@replicator = ContainerReplicator.where(:name => "monitoring-influx-grafana-controller").first
expect(@replicator).to have_attributes(
:name => "monitoring-influx-grafana-controller",
Expand All @@ -291,7 +298,8 @@ def assert_specific_container_replicator
)
if check_tag_mapping
expect(@replicator.tags).to contain_exactly(
tag_in_category_with_description(@name_category, "influxGrafana")
tag_in_category_with_description(@name_category, "influxGrafana"),
*expected_extra_tags
)
end
expect(@replicator.selector_parts.count).to eq(1)
Expand Down

0 comments on commit 54595b6

Please sign in to comment.