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/metadata_test.go
lndrschlz e60bdb94a6
feat(uiVeri5): golang implmementation for uiVeri5ExecuteTests (#2394)
* added uiVeri5ExecuteTests step files

* added confPath an regenerated step

* added test for uiVeri5ExecuteTests

* config modified

* added groovy wrapper

* ambiguous method fixed

* uiveri5 wrapper

* removed install command

* fixed defaults

* added testOptions as confPath arg

* test set env

* test npm install local

* changed env settings

* tests regenerated

* go generate

* fix code climate

* overwrite groovy step

* remove groovy wrapper go

* unstash piper bin

* test older node version

* test piperExecuteBin

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* refactored params

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* set testServerUrl as os env for uiveri5

* Update config.yml

* fix naming of testServerUrl param

* wip

* refactored setEnv and fixed tests

* wip

* step param for NPM_CONFIG_PREFIX

* fix runCommand

* refactored step param, regenerate, docu, fix tests

* fix groovy wrapper test

* cleanup

* add to CommonStepsTest field whitelist

* fixed default pipeline environment vars

* fix []string default

* fix metadata.go bug

* added test for docu metadata gen

* fix metadata_test.go in doc gen

* Update metadata_generated.go

* Update metadata_generated.go

* remove npm config prefix param; doc fix

* remove tab

* changed npm config prefix

* removed groovy wrapper test

* removed groovy step defaults

* modify path variable

* modified npm config prefix

* fix error wrapper and tests

* doc update

* add testRepository support

* wip

* fix testRepository param

* wip

* add utils

* init stash content

* wip

* wip

* wip

* add comment for deprecated parameters

* fixed commonStepTest

* fixed commonStepTest

* added error category for testOptions failure

* Update vars/uiVeri5ExecuteTests.groovy

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* Update vars/uiVeri5ExecuteTests.groovy

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* fix condition

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-01-28 11:31:24 +01:00

123 lines
4.2 KiB
Go

package generator
import (
"testing"
"github.com/SAP/jenkins-library/pkg/config"
"github.com/stretchr/testify/assert"
)
func Test_adjustDefaultValues(t *testing.T) {
tests := []struct {
want interface{}
name string
input *config.StepData
}{
{want: false, name: "boolean", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "bool", Mandatory: true},
}}}}},
{want: nil, name: "integer", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "int", Mandatory: true},
}}}}},
{want: nil, name: "string", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "string", Mandatory: true},
}}}}},
{want: nil, name: "string array", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "[]string", Mandatory: true},
}}}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// test
adjustDefaultValues(tt.input)
// assert
assert.Equal(t, tt.want, tt.input.Spec.Inputs.Parameters[0].Default)
})
}
}
func Test_adjustMandatoryFlags(t *testing.T) {
tests := []struct {
want bool
name string
input *config.StepData
}{
{want: false, name: "boolean with empty default", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "bool", Mandatory: true, Default: false},
}}}}},
{want: false, name: "boolean with default", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "bool", Mandatory: true, Default: true},
}}}}},
{want: true, name: "string with default not set", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "string", Mandatory: true},
}}}}},
{want: true, name: "string with empty default", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "string", Mandatory: true, Default: ""},
}}}}},
{want: false, name: "string with default", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "string", Mandatory: true, Default: "Oktober"},
}}}}},
{want: true, name: "string array with default not set", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "[]string", Mandatory: true},
}}}}},
{want: true, name: "string array with empty default", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "[]string", Mandatory: true, Default: []string{}},
}}}}},
{want: false, name: "string array with default", input: &config.StepData{Spec: config.StepSpec{Inputs: config.StepInputs{Parameters: []config.StepParameters{
{Name: "param", Type: "[]string", Mandatory: true, Default: []string{"Oktober"}},
}}}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// test
adjustMandatoryFlags(tt.input)
// assert
assert.Equal(t, tt.want, tt.input.Spec.Inputs.Parameters[0].Mandatory)
})
}
}
func Test_interfaceArrayLength(t *testing.T) {
type args struct {
i interface{}
}
tests := []struct {
name string
args args
want int
}{
{
name: "empty type",
args: args{},
want: -1,
},
{
name: "string type",
args: args{"string"},
want: -1,
},
{
name: "empty array type",
args: args{[]interface{}{}},
want: 0,
},
{
name: "string array type",
args: args{[]interface{}{"string1", "string1"}},
want: 2,
},
{
name: "string array type",
args: args{[]string{"string1", "string1"}},
want: 2,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := interfaceArrayLength(tt.args.i); got != tt.want {
t.Errorf("interfaceArrayLength() = %v, want %v", got, tt.want)
}
})
}
}