added documentation_matchers.go generation

This commit is contained in:
Manuel Carmona
2017-04-10 11:30:23 +02:00
parent d66beade34
commit ca3ae587f3
11 changed files with 250 additions and 34 deletions

View File

@ -10,31 +10,37 @@ import (
)
const (
commitTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
// FromFile test
formatedLangGold = "test_files/formated_languages.gold"
formatedContentGold = "test_files/formated_content.gold"
formatedVendorGold = "test_files/formated_vendor.gold"
formatedLangGold = "test_files/formated_languages.gold"
formatedContentGold = "test_files/formated_content.gold"
formatedVendorGold = "test_files/formated_vendor.gold"
formatedDocumentationGold = "test_files/formated_documentation.gold"
// Languages test
ymlTestFile = "test_files/languages.test.yml"
langGold = "test_files/languages.gold"
languagesTestTmplPath = "test_files/languages.test.tmpl"
languagesTestTmplName = "languages.test.tmpl"
commitLangTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
// Heuristics test
heuristicsTestFile = "test_files/heuristics.test.rb"
contentGold = "test_files/content.gold"
contentTestTmplPath = "test_files/content.test.go.tmpl"
contentTestTmplName = "content.test.go.tmpl"
commitHeuristicsTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
heuristicsTestFile = "test_files/heuristics.test.rb"
contentGold = "test_files/content.gold"
contentTestTmplPath = "test_files/content.test.go.tmpl"
contentTestTmplName = "content.test.go.tmpl"
// Vendor test
vendorTestFile = "test_files/vendor.test.yml"
vendorGold = "test_files/vendor.gold"
vendorTestTmplPath = "test_files/vendor.test.go.tmpl"
vendorTestTmplName = "vendor.test.go.tmpl"
commitVendorTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
// Documentation test
documentationTestFile = "test_files/documentation.test.yml"
documentationGold = "test_files/documentation.gold"
documentationTestTmplPath = "test_files/documentation.test.go.tmpl"
documentationTestTmplName = "documentation.test.go.tmpl"
)
func TestFromFile(t *testing.T) {
@ -47,6 +53,9 @@ func TestFromFile(t *testing.T) {
goldVendor, err := ioutil.ReadFile(formatedVendorGold)
assert.NoError(t, err)
goldDocumentation, err := ioutil.ReadFile(formatedDocumentationGold)
assert.NoError(t, err)
outPathLang, err := ioutil.TempFile("/tmp", "generator-test-")
assert.NoError(t, err)
defer os.Remove(outPathLang.Name())
@ -57,7 +66,11 @@ func TestFromFile(t *testing.T) {
outPathVendor, err := ioutil.TempFile("/tmp", "generator-test-")
assert.NoError(t, err)
defer os.Remove(outPathContent.Name())
defer os.Remove(outPathVendor.Name())
outPathDocumentation, err := ioutil.TempFile("/tmp", "generator-test-")
assert.NoError(t, err)
defer os.Remove(outPathDocumentation.Name())
tests := []struct {
name string
@ -75,7 +88,7 @@ func TestFromFile(t *testing.T) {
outPath: outPathLang.Name(),
tmplPath: languagesTestTmplPath,
tmplName: languagesTestTmplName,
commit: commitLangTest,
commit: commitTest,
generate: Languages,
wantOut: goldLang,
},
@ -85,7 +98,7 @@ func TestFromFile(t *testing.T) {
outPath: outPathContent.Name(),
tmplPath: contentTestTmplPath,
tmplName: contentTestTmplName,
commit: commitHeuristicsTest,
commit: commitTest,
generate: Heuristics,
wantOut: goldContent,
},
@ -95,10 +108,20 @@ func TestFromFile(t *testing.T) {
outPath: outPathVendor.Name(),
tmplPath: vendorTestTmplPath,
tmplName: vendorTestTmplName,
commit: commitVendorTest,
commit: commitTest,
generate: Vendor,
wantOut: goldVendor,
},
{
name: "TestFromFile_Documentation",
fileToParse: documentationTestFile,
outPath: outPathDocumentation.Name(),
tmplPath: documentationTestTmplPath,
tmplName: documentationTestTmplName,
commit: commitTest,
generate: Documentation,
wantOut: goldDocumentation,
},
}
for _, tt := range tests {
@ -132,7 +155,7 @@ func TestLanguages(t *testing.T) {
input: input,
tmplPath: languagesTestTmplPath,
tmplName: languagesTestTmplName,
commit: commitLangTest,
commit: commitTest,
wantOut: gold,
},
}
@ -166,7 +189,7 @@ func TestHeuristics(t *testing.T) {
input: input,
tmplPath: contentTestTmplPath,
tmplName: contentTestTmplName,
commit: commitHeuristicsTest,
commit: commitTest,
wantOut: gold,
},
}
@ -200,7 +223,7 @@ func TestVendor(t *testing.T) {
input: input,
tmplPath: vendorTestTmplPath,
tmplName: vendorTestTmplName,
commit: commitVendorTest,
commit: commitTest,
wantOut: gold,
},
}
@ -213,3 +236,37 @@ func TestVendor(t *testing.T) {
})
}
}
func TestDocumentation(t *testing.T) {
gold, err := ioutil.ReadFile(documentationGold)
assert.NoError(t, err)
input, err := ioutil.ReadFile(documentationTestFile)
assert.NoError(t, err)
tests := []struct {
name string
input []byte
tmplPath string
tmplName string
commit string
wantOut []byte
}{
{
name: "TestDocumentation",
input: input,
tmplPath: documentationTestTmplPath,
tmplName: documentationTestTmplName,
commit: commitTest,
wantOut: gold,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out, err := Documentation(tt.input, tt.tmplPath, tt.tmplName, tt.commit)
assert.NoError(t, err)
assert.EqualValues(t, tt.wantOut, out, fmt.Sprintf("Documentation() = %v, want %v", string(out), string(tt.wantOut)))
})
}
}