1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/piperutils/pointer_test.go
Googlom 3744787348
chore(refactor): Switch GitHub actions provider to use github sdk (#4563)
* refactor github package and use builder pattern for client

* switch to github package

* some renamings

* fix panic on uninitialized provider

* fix according to review comments

---------

Co-authored-by: Gulom Alimov <gulomjon.alimov@sap.com>
Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com>
2023-09-20 09:38:45 +00:00

63 lines
977 B
Go

//go:build unit
// +build unit
package piperutils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSafeDereferenceString(t *testing.T) {
type testCase[T any] struct {
name string
p *T
want T
}
str := "test"
tests := []testCase[string]{
{
name: "nil",
p: nil,
want: "",
},
{
name: "non-nil",
p: &str,
want: "test",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, SafeDereference(tt.p), "SafeDereference(%v)", tt.p)
})
}
}
func TestSafeDereferenceInt64(t *testing.T) {
type testCase[T any] struct {
name string
p *T
want T
}
i64 := int64(111)
tests := []testCase[int64]{
{
name: "nil",
p: nil,
want: 0,
},
{
name: "non-nil",
p: &i64,
want: 111,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, SafeDereference(tt.p), "SafeDereference(%v)", tt.p)
})
}
}