Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit b034203

Browse files
committed
Handle DeepCopy of zero value versions
1 parent f284870 commit b034203

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/cassandra/version/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ func (v Version) MarshalJSON() ([]byte, error) {
7676
var _ json.Marshaler = &Version{}
7777

7878
// DeepCopy returns a deep-copy of the Version value.
79+
// If the underlying semver is a nil pointer, assume that the zero value is being copied,
80+
// and return that.
7981
func (v Version) DeepCopy() Version {
82+
if v.semver == nil {
83+
return Version{}
84+
}
8085
return *New(v.String())
8186
}

pkg/cassandra/version/version_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,18 @@ func TestUnmarshalJSON(t *testing.T) {
9393
)
9494
}
9595
}
96+
97+
func TestDeepCopy(t *testing.T) {
98+
t.Run(
99+
"zero value",
100+
func(t *testing.T) {
101+
t.Log(version.Version{}.DeepCopy())
102+
},
103+
)
104+
t.Run(
105+
"validated version",
106+
func(t *testing.T) {
107+
t.Log(version.New("3.11.2").DeepCopy())
108+
},
109+
)
110+
}

0 commit comments

Comments
 (0)