Skip to content

Commit

Permalink
Merge pull request #7 from nellyc/polarion_required_fields
Browse files Browse the repository at this point in the history
Polarion TC importer - added required fields for approval
  • Loading branch information
Artyom Lukianov authored May 10, 2018
2 parents 80f4b01 + 67fabd9 commit 51aa15b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 14 additions & 4 deletions pkg/polarion-generator/test_cases_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func parseIt(testcase *polarion_xml.TestCase, block *ginkgoBlock, funcBody *ast.
})
}

func parseTable(testcases *polarion_xml.TestCases, block *ginkgoBlock, exprs []ast.Expr, customFields *polarion_xml.TestCaseCustomFields) {
func parseTable(testcases *polarion_xml.TestCases, block *ginkgoBlock, exprs []ast.Expr, customFields *polarion_xml.TestCaseCustomFields, filename string) {
lit := exprs[0].(*ast.BasicLit)
baseName := strings.Trim(lit.Value, "\"")

Expand Down Expand Up @@ -219,6 +219,10 @@ func parseTable(testcases *polarion_xml.TestCases, block *ginkgoBlock, exprs []a
}
addCustomField(&testCase.TestCaseCustomFields, "caseautomation", "automated")
addCustomField(&testCase.TestCaseCustomFields, "testtype", "functional")
addCustomField(&testCase.TestCaseCustomFields, "subtype1", "-")
addCustomField(&testCase.TestCaseCustomFields, "subtype2", "-")
addCustomField(&testCase.TestCaseCustomFields, "status-id", "proposed")
addCustomField(&testCase.TestCaseCustomFields, "automation_script", filename)
addCustomField(&testCase.TestCaseCustomFields, "upstream", "yes")
testcases.TestCases = append(testcases.TestCases, *testCase)
}
Expand Down Expand Up @@ -259,7 +263,7 @@ func isFieldValueSupported(value string, supportedValues []string) bool {
}

// FillPolarionTestCases parse ginkgo format test and fill polarion test cases struct accordingly
func FillPolarionTestCases(f *ast.File, testCases *polarion_xml.TestCases, commentMap *ast.CommentMap) error {
func FillPolarionTestCases(f *ast.File, testCases *polarion_xml.TestCases, commentMap *ast.CommentMap, filename string) error {
var block *ginkgoBlock

ast.Inspect(f, func(n ast.Node) bool {
Expand Down Expand Up @@ -329,7 +333,7 @@ func FillPolarionTestCases(f *ast.File, testCases *polarion_xml.TestCases, comme
case ginkgoTable:
customFields := polarion_xml.TestCaseCustomFields{}
parseComments(x, commentMap, &customFields)
parseTable(testCases, block, x.Args, &customFields)
parseTable(testCases, block, x.Args, &customFields, filename)
return false
case ginkgoIt, ginkgoSpecify:
for i := len(block.rparenPos) - 1; i >= 0; i-- {
Expand All @@ -347,6 +351,10 @@ func FillPolarionTestCases(f *ast.File, testCases *polarion_xml.TestCases, comme
customFields := polarion_xml.TestCaseCustomFields{}
addCustomField(&customFields, "caseautomation", "automated")
addCustomField(&customFields, "testtype", "functional")
addCustomField(&customFields, "subtype1", "-")
addCustomField(&customFields, "subtype2", "-")
addCustomField(&customFields, "status-id", "proposed")
addCustomField(&customFields, "automation_script", filename)
addCustomField(&customFields, "upstream", "yes")
testCase := polarion_xml.TestCase{
Title: polarion_xml.Title{Content: title},
Expand Down Expand Up @@ -417,7 +425,9 @@ func main() {
cmap := ast.NewCommentMap(fset, f, f.Comments)

// fill polarion test cases struct
FillPolarionTestCases(f, testCases, &cmap)
pathToFile := strings.Split(file, "/")
filenameShort := pathToFile[len(pathToFile)-1]
FillPolarionTestCases(f, testCases, &cmap, filenameShort)
}

// generate polarion test cases XML file
Expand Down
18 changes: 17 additions & 1 deletion pkg/polarion-generator/test_cases_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var _ = Describe("Test Case Generator", func() {
cmap := ast.NewCommentMap(fset, f, f.Comments)

testCases = &polarion_xml.TestCases{}
FillPolarionTestCases(f, testCases, &cmap)
FillPolarionTestCases(f, testCases, &cmap, "")

Expect(len(testCases.TestCases)).To(Equal(4))
})
Expand Down Expand Up @@ -239,6 +239,10 @@ var _ = Describe("Test Case Generator", func() {
{Content: "medium", ID: "caseimportance"},
{Content: "automated", ID: "caseautomation"},
{Content: "functional", ID: "testtype"},
{Content: "-", ID: "subtype1"},
{Content: "-", ID: "subtype2"},
{Content: "proposed", ID: "status-id"},
{Content: "", ID: "automation_script"},
{Content: "yes", ID: "upstream"},
},
},
Expand All @@ -248,13 +252,21 @@ var _ = Describe("Test Case Generator", func() {
{Content: "medium", ID: "caseimportance"},
{Content: "automated", ID: "caseautomation"},
{Content: "functional", ID: "testtype"},
{Content: "-", ID: "subtype1"},
{Content: "-", ID: "subtype2"},
{Content: "proposed", ID: "status-id"},
{Content: "", ID: "automation_script"},
{Content: "yes", ID: "upstream"},
},
},
2: {
CustomFields: []polarion_xml.TestCaseCustomField{
{Content: "automated", ID: "caseautomation"},
{Content: "functional", ID: "testtype"},
{Content: "-", ID: "subtype1"},
{Content: "-", ID: "subtype2"},
{Content: "proposed", ID: "status-id"},
{Content: "", ID: "automation_script"},
{Content: "yes", ID: "upstream"},
{Content: "critical", ID: "caseimportance"},
{Content: "negative", ID: "caseposneg"},
Expand All @@ -264,6 +276,10 @@ var _ = Describe("Test Case Generator", func() {
CustomFields: []polarion_xml.TestCaseCustomField{
{Content: "automated", ID: "caseautomation"},
{Content: "functional", ID: "testtype"},
{Content: "-", ID: "subtype1"},
{Content: "-", ID: "subtype2"},
{Content: "proposed", ID: "status-id"},
{Content: "", ID: "automation_script"},
{Content: "yes", ID: "upstream"},
{Content: "low", ID: "caseimportance"},
},
Expand Down

0 comments on commit 51aa15b

Please sign in to comment.