1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-31 22:05:11 +02:00
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution ()
* 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

68 lines
1.4 KiB
Go

//go:build unit
// +build unit
package validation
import (
"github.com/stretchr/testify/assert"
"testing"
)
type Connection struct {
Endpoint string
User string
Password string
}
type Dummy struct {
Connection Connection
Prop1 string
Prop2 string
Prop3 string
Bool1 bool
Int1 int64
List []string
}
func TestWeProvideNotAStruct(t *testing.T) {
_, err := FindEmptyStringsInConfigStruct("Hello World")
assert.EqualError(t, err, "'Hello World' (string) is not a struct")
}
func TestUnsupportedType(t *testing.T) {
type DummyWithUnsupportedType struct {
Dummy
NotExpected float32
}
_, err := FindEmptyStringsInConfigStruct(DummyWithUnsupportedType{})
assert.EqualError(t, err, "unexpected type 'float32' of field: 'NotExpected', value: '0'")
}
func TestFindEmptyStringsInConfig(t *testing.T) {
myStruct := Dummy{
Connection: Connection{
Endpoint: "<set>",
User: "",
Password: "<set>",
},
Prop1: "<set>",
Prop2: "", // this is empty
// Prop3: "this is missing intentionally"
Bool1: false,
Int1: 42,
List: []string{"1", "2"},
}
emptyStrings, err := FindEmptyStringsInConfigStruct(myStruct)
if assert.NoError(t, err) {
assert.Len(t, emptyStrings, 3)
assert.Subset(t, emptyStrings, []string{
"Connection.User", // empty value, nested
"Prop2", // empty value
"Prop3", // missing value
})
}
}