1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/documentation/generator/description_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

76 lines
2.2 KiB
Go

//go:build unit
// +build unit
package generator
import (
"testing"
"github.com/SAP/jenkins-library/pkg/config"
"github.com/stretchr/testify/assert"
)
func TestCreateStepName(t *testing.T) {
tests := []struct {
name string
input *config.StepData
want string
}{
{
name: "simple step name section",
input: &config.StepData{
Metadata: config.StepMetadata{Name: "teststep", Description: "TestDescription"},
},
want: "# teststep\n\nTestDescription\n",
},
}
for _, testcase := range tests {
t.Run(testcase.name, func(t *testing.T) {
assert.Equal(t, testcase.want, createStepName(testcase.input))
})
}
}
func TestCreateDescriptionSection(t *testing.T) {
CustomLibrarySteps = []CustomLibrary{{
Name: "TestLibrary",
BinaryName: "myBinary",
LibraryName: "myLibrary",
Steps: []string{"myCustomStep"},
}}
tests := []struct {
name string
input *config.StepData
want string
}{
{
name: "simple step description section",
input: &config.StepData{
Metadata: config.StepMetadata{Name: "teststep", LongDescription: "TestDescription"},
},
want: headlineDescription + "TestDescription" + "\n\n" +
headlineUsage + configRecommendation + "\n\n" +
"!!! tip \"\"" + "\n\n" +
headlineJenkinsPipeline + " ```groovy\n library('piper-lib-os')\n\n teststep script: this\n ```" + "\n\n" +
headlineCommandLine + " ```sh\n piper teststep\n ```" + "\n\n",
},
{
name: "custom step description section",
input: &config.StepData{
Metadata: config.StepMetadata{Name: "myCustomStep", LongDescription: "TestDescription"},
},
want: headlineDescription + "TestDescription" + "\n\n" +
headlineUsage + configRecommendation + "\n\n" +
"!!! tip \"\"" + "\n\n" +
headlineJenkinsPipeline + " ```groovy\n library('myLibrary')\n\n myCustomStep script: this\n ```" + "\n\n" +
headlineCommandLine + " ```sh\n myBinary myCustomStep\n ```" + "\n\n",
},
}
for _, testcase := range tests {
t.Run(testcase.name, func(t *testing.T) {
assert.Equal(t, testcase.want, createDescriptionSection(testcase.input))
})
}
}