Skip to content

Commit

Permalink
Integration test results
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Oct 17, 2024
1 parent 4e94ed7 commit de41a5b
Show file tree
Hide file tree
Showing 2 changed files with 452 additions and 6 deletions.
244 changes: 241 additions & 3 deletions tests/jenkins/TestPublishIntegTestResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ class TestPublishIntegTestResults extends BuildPipelineTest {
"without_security_test_stderr": {
"type": "keyword"
}
},
"aliases": {
"opensearch-integration-test-results": {}
}
}
}'
Expand All @@ -170,6 +167,22 @@ class TestPublishIntegTestResults extends BuildPipelineTest {
create_index_response=$(curl -s -XPUT "METRICS_HOST_URL/test-index" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H 'Content-Type: application/json' -d "${INDEX_MAPPING}")
if [[ $create_index_response == *'"acknowledged":true'* ]]; then
echo "Index created successfully."
echo "Updating alias..."
update_alias_response=\$(curl -s -XPOST "METRICS_HOST_URL/_aliases" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H "Content-Type: application/json" -d '{
"actions": [
{
"add": {
"index": "test-index",
"alias": "opensearch-integration-test-results"
}
}
]
}')
if [[ \$update_alias_response == *'"acknowledged":true'* ]]; then
echo "Alias updated successfully."
else
echo "Failed to update alias. Error message: \$update_alias_response"
fi
else
echo "Failed to create index. Error message: $create_index_response"
exit 1
Expand All @@ -185,6 +198,132 @@ class TestPublishIntegTestResults extends BuildPipelineTest {
assert normalizeString(calledCommands[0]) == normalizeString(expectedCommandBlock)
}

@Test
void testIndexTestFailuresData() {
def indexName = 'opensearch-integration-test-failures-test-index'
def testRecordsFile = 'test-failures.json'

def script = loadScript('vars/publishIntegTestResults.groovy')

def calledCommands = new ArrayList()
script.metaClass.sh = { String command ->
calledCommands << command
if (command.contains("curl -I")) {
return "HTTP/1.1 200 OK"
} else if (command.contains("curl -s -XPUT") && command.contains(indexName)) {
return '{"acknowledged":true}'
} else if (command.contains("curl -XPOST") && command.contains(indexName)) {
return '{"took":10, "errors":false}'
} else {
throw new IllegalArgumentException("Unexpected command: $command")
}
}

script.indexTestFailuresData(indexName, testRecordsFile)

def expectedCommandBlock = '''set +e
set +x
echo "INDEX NAME IS opensearch-integration-test-failures-test-index"
INDEX_MAPPING='{
"mappings": {
"properties": {
"component": {
"type": "keyword"
},
"component_repo": {
"type": "keyword"
},
"component_repo_url": {
"type": "keyword"
},
"version": {
"type": "keyword"
},
"integ_test_build_number": {
"type": "integer"
},
"integ_test_build_url": {
"type": "keyword"
},
"distribution_build_number": {
"type": "integer"
},
"distribution_build_url": {
"type": "keyword"
},
"build_start_time": {
"type": "date",
"format": "epoch_millis"
},
"rc": {
"type": "keyword"
},
"rc_number": {
"type": "integer"
},
"platform": {
"type": "keyword"
},
"architecture": {
"type": "keyword"
},
"distribution": {
"type": "keyword"
},
"component_category": {
"type": "keyword"
},
"test_type": {
"type": "keyword"
},
"test_class": {
"type": "keyword"
},
"test_name": {
"type": "keyword"
}
}
}
}'
curl -I "METRICS_HOST_URL/opensearch-integration-test-failures-test-index" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" | grep -E "HTTP\\/[0-9]+(\\.[0-9]+)? 200"
if [ $? -eq 0 ]; then
echo "Index already exists. Indexing Results"
else
echo "Index does not exist. Creating..."
create_index_response=$(curl -s -XPUT "METRICS_HOST_URL/opensearch-integration-test-failures-test-index" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H 'Content-Type: application/json' -d "${INDEX_MAPPING}")
if [[ $create_index_response == *'"acknowledged":true'* ]]; then
echo "Index created successfully."
echo "Updating alias..."
update_alias_response=$(curl -s -XPOST "METRICS_HOST_URL/_aliases" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H "Content-Type: application/json" -d '{
"actions": [
{
"add": {
"index": "opensearch-integration-test-failures-test-index",
"alias": "opensearch-integration-test-failures"
}
}
]
}')
if [[ $update_alias_response == *'"acknowledged":true'* ]]; then
echo "Alias updated successfully."
else
echo "Failed to update alias. Error message: $update_alias_response"
fi
else
echo "Failed to create index. Error message: $create_index_response"
exit 1
fi
fi
if [ -s test-failures.json ]; then
echo "File Exists, indexing results."
curl -XPOST "METRICS_HOST_URL/opensearch-integration-test-failures-test-index/_bulk" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H "Content-Type: application/x-ndjson" --data-binary "@test-failures.json"
else
echo "File Does not exist. No tests records to process."
fi'''

assert calledCommands.size() == 1
assert normalizeString(calledCommands[0]) == normalizeString(expectedCommandBlock)
}

@Test
void testGenerateJson() {
Expand Down Expand Up @@ -235,6 +374,105 @@ class TestPublishIntegTestResults extends BuildPipelineTest {
assert parsedResult == expectedJson
}

@Test
void testGenerateFailedTestJson() {
def script = loadScript('vars/publishIntegTestResults.groovy')

def result = script.generatefailedTestJson(
'component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test_category',
'test_type', 'test_class', 'test_name'
)

def parsedResult = new JsonSlurper().parseText(result)
def expectedJson = [
component: 'component1',
component_repo: 'componentRepo',
component_repo_url: 'https://componentRepoUrl',
version: '1.0',
integ_test_build_number: 123,
integ_test_build_url: 'http://example.com/build/123',
distribution_build_number: 456,
distribution_build_url: 'http://example.com/distribution/456',
rc: 'rc1',
rc_number: 1,
platform: 'linux',
architecture: 'x64',
distribution: 'tar',
component_category: 'test_category',
test_type: 'test_type',
test_class: 'test_class',
test_name: 'test_name'
]

// Remove the dynamic field for comparison
parsedResult.remove('build_start_time')
assert parsedResult == expectedJson
}

/*@Test
void testProcessFailedTests_EmptyResults() {
def script = loadScript('vars/publishIntegTestResults.groovy')
script.processFailedTests(
[], 'component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test-category',
'security-pass', 'test-failures-index'
)
assert script.getLastOutput().contains("Empty Results")
}
@Test
void testProcessFailedTests_TestResultNotAvailable() {
def script = loadScript('vars/publishIntegTestResults.groovy')
script.processFailedTests(
['Test Result Not Available'], 'component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test-category',
'security-fail', 'test-failures-index'
)
def expectedJsonContent = script.generatefailedTestJson('component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test-category', 'security-fail', 'Not Available', 'Not Available')
assert script.getLastOutput().contains("test-failures.json")
assert script.getLastOutput().contains("indexTestFailuresData")
}
@Test
void testProcessFailedTests_NoFailedTest() {
def script = loadScript('vars/publishIntegTestResults.groovy')
script.processFailedTests(
['No Failed Test'], 'component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test-category',
'security-pass', 'test-failures-index'
)
assert script.getLastOutput().contains("Tests Passed")
}
@Test
void testProcessFailedTests_WithFailedTests() {
def script = loadScript('vars/publishIntegTestResults.groovy')
script.processFailedTests(
['com.example.TestClass#testMethod'], 'component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test-category',
'security-fail', 'test-failures-index'
)
def expectedJsonContent = script.generatefailedTestJson('component1', 'componentRepo', 'https://componentRepoUrl', '1.0', 123,
'http://example.com/build/123', 456, 'http://example.com/distribution/456',
System.currentTimeMillis(), 'rc1', 1, 'linux', 'x64', 'tar', 'test-category', 'security-fail', 'TestClass', 'testMethod')
assert script.getLastOutput().contains("test-failures.json")
assert script.getLastOutput().contains("indexTestFailuresData")
}*/




@Test
void testComponentResultWithSecurityFail() {
def withSecurity = 'fail'
Expand Down
Loading

0 comments on commit de41a5b

Please sign in to comment.