Skip to content

Commit c719a8b

Browse files
authored
ensure nil is returned in case of nil input (#47)
1 parent 5f84115 commit c719a8b

File tree

4 files changed

+77
-14
lines changed

4 files changed

+77
-14
lines changed

api/rest/mapper/mapper.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,16 @@ func unwrapInt32(w *wrapperspb.Int32Value) *int32 {
241241
}
242242

243243
func mustTimestampToTime(ts *timestamppb.Timestamp) *time.Time {
244+
if ts == nil {
245+
return nil
246+
}
244247
t := ts.AsTime()
245248
return &t
246249
}
247250

248251
func mustTimeToTimestamp(t *time.Time) *timestamppb.Timestamp {
252+
if t == nil {
253+
return nil
254+
}
249255
return timestamppb.New(*t)
250256
}

api/rest/mapper/mapper_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ func TestTenantMapperRoundtrip(t *testing.T) {
9797
},
9898
},
9999
},
100+
{
101+
name: "nil times",
102+
inAndOut: &v1.Tenant{
103+
Meta: &v1.Meta{
104+
Id: "1",
105+
Kind: "tenant",
106+
Apiversion: "1",
107+
Version: 99,
108+
CreatedTime: nil,
109+
UpdatedTime: nil,
110+
},
111+
Name: "tnt",
112+
Description: "tnt is a test tenant",
113+
IAMConfig: &v1.IAMConfig{
114+
IssuerConfig: &v1.IssuerConfig{
115+
URL: "https://oidc.myissuer.com",
116+
ClientID: "47abcdef12",
117+
},
118+
IDMConfig: &v1.IDMConfig{
119+
IDMType: "ldap",
120+
},
121+
},
122+
},
123+
},
100124
}
101125
for _, tt := range tests {
102126
tt := tt

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/spf13/cobra v1.1.3
2424
github.com/spf13/viper v1.7.1
2525
github.com/stretchr/testify v1.7.0
26-
github.com/testcontainers/testcontainers-go v0.10.0
26+
github.com/testcontainers/testcontainers-go v0.11.0
2727
go.uber.org/zap v1.17.0
2828
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
2929
google.golang.org/grpc v1.38.0

0 commit comments

Comments
 (0)