Skip to content

Commit 8b9bf62

Browse files
authored
fix(apt): fix missing Ceph Squid (#2318)
* fix(apt): fix missing Ceph Squid Signed-off-by: Maciej Lech <[email protected]> * fix(apt): use require in new tests Signed-off-by: Maciej Lech <[email protected]> --------- Signed-off-by: Maciej Lech <[email protected]>
1 parent 7e4f421 commit 8b9bf62

File tree

3 files changed

+202
-4
lines changed

3 files changed

+202
-4
lines changed

fwprovider/types/nodes/apt/standard_repo_handle_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestStandardRepoHandleValueFromTerraform(t *testing.T) {
4444
val.ValueString() == "ceph-foo-enterprise"
4545
},
4646
},
47-
"valid Ceph APT standard repository handle": {
47+
`valid Ceph "enterprise" APT standard repository handle`: {
4848
val: tftypes.NewValue(tftypes.String, "ceph-quincy-enterprise"),
4949
expected: func(val StandardRepoHandleValue) bool {
5050
return val.kind == apitypes.StandardRepoHandleKindEnterprise &&
@@ -55,15 +55,26 @@ func TestStandardRepoHandleValueFromTerraform(t *testing.T) {
5555
val.ValueString() == "ceph-quincy-enterprise"
5656
},
5757
},
58+
`valid Ceph "no subscription" APT standard repository handle`: {
59+
val: tftypes.NewValue(tftypes.String, "ceph-reef-no-subscription"),
60+
expected: func(val StandardRepoHandleValue) bool {
61+
return val.kind == apitypes.StandardRepoHandleKindNoSubscription &&
62+
val.CephVersionName() == apitypes.CephVersionNameReef &&
63+
val.IsCephHandle() &&
64+
val.IsSupportedFilePath(apitypes.StandardRepoFilePathCeph) &&
65+
val.ComponentName() == "no-subscription" &&
66+
val.ValueString() == "ceph-reef-no-subscription"
67+
},
68+
},
5869
`valid Ceph "test" APT standard repository handle`: {
59-
val: tftypes.NewValue(tftypes.String, "ceph-reef-test"),
70+
val: tftypes.NewValue(tftypes.String, "ceph-squid-test"),
6071
expected: func(val StandardRepoHandleValue) bool {
6172
return val.kind == apitypes.StandardRepoHandleKindTest &&
62-
val.CephVersionName() == apitypes.CephVersionNameReef &&
73+
val.CephVersionName() == apitypes.CephVersionNameSquid &&
6374
val.IsCephHandle() &&
6475
val.IsSupportedFilePath(apitypes.StandardRepoFilePathCeph) &&
6576
val.ComponentName() == "test" &&
66-
val.ValueString() == "ceph-reef-test"
77+
val.ValueString() == "ceph-squid-test"
6778
},
6879
},
6980
"invalid APT repository handle": {

proxmox/types/nodes/apt/repositories/ceph_version_name.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var (
3131
// CephVersionNameReef is the name for the "Reef" Ceph major version.
3232
CephVersionNameReef = CephVersionName{"reef"}
3333

34+
// CephVersionNameSquid is the name for the "Squid" Ceph major version.
35+
CephVersionNameSquid = CephVersionName{"squid"}
36+
3437
// CephVersionNameUnknown is the name for an unknown Ceph major version.
3538
CephVersionNameUnknown = CephVersionName{"unknown"}
3639
)
@@ -99,6 +102,8 @@ func ParseCephVersionName(input string) (CephVersionName, error) {
99102
return CephVersionNameQuincy, nil
100103
case CephVersionNameReef.String():
101104
return CephVersionNameReef, nil
105+
case CephVersionNameSquid.String():
106+
return CephVersionNameSquid, nil
102107
default:
103108
return CephVersionName{}, ErrCephVersionNameIllegal(input)
104109
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
This Source Code Form is subject to the terms of the Mozilla Public
3+
License, v. 2.0. If a copy of the MPL was not distributed with this
4+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
package repositories
8+
9+
import (
10+
"encoding/json"
11+
"testing"
12+
13+
"github.com/stretchr/testify/require"
14+
)
15+
16+
func TestParseCephVersionName(t *testing.T) {
17+
t.Parallel()
18+
19+
tests := map[string]struct {
20+
input string
21+
expected CephVersionName
22+
expectError bool
23+
}{
24+
"quincy": {
25+
input: "quincy",
26+
expected: CephVersionNameQuincy,
27+
},
28+
"reef": {
29+
input: "reef",
30+
expected: CephVersionNameReef,
31+
},
32+
"squid": {
33+
input: "squid",
34+
expected: CephVersionNameSquid,
35+
},
36+
"invalid": {
37+
input: "invalid",
38+
expectError: true,
39+
},
40+
"empty": {
41+
input: "",
42+
expectError: true,
43+
},
44+
"uppercase": {
45+
input: "QUINCY",
46+
expectError: true,
47+
},
48+
}
49+
50+
for name, test := range tests {
51+
t.Run(name, func(t *testing.T) {
52+
t.Parallel()
53+
54+
result, err := ParseCephVersionName(test.input)
55+
56+
if test.expectError {
57+
require.Error(t, err)
58+
} else {
59+
require.NoError(t, err)
60+
require.Equal(t, test.expected, result)
61+
}
62+
})
63+
}
64+
}
65+
66+
func TestCephVersionNameString(t *testing.T) {
67+
t.Parallel()
68+
69+
tests := map[string]struct {
70+
version CephVersionName
71+
expected string
72+
}{
73+
"quincy": {
74+
version: CephVersionNameQuincy,
75+
expected: "quincy",
76+
},
77+
"reef": {
78+
version: CephVersionNameReef,
79+
expected: "reef",
80+
},
81+
"squid": {
82+
version: CephVersionNameSquid,
83+
expected: "squid",
84+
},
85+
"unknown": {
86+
version: CephVersionNameUnknown,
87+
expected: "unknown",
88+
},
89+
}
90+
91+
for name, test := range tests {
92+
t.Run(name, func(t *testing.T) {
93+
t.Parallel()
94+
95+
result := test.version.String()
96+
require.Equal(t, test.expected, result)
97+
})
98+
}
99+
}
100+
101+
func TestCephVersionNameMarshalJSON(t *testing.T) {
102+
t.Parallel()
103+
104+
tests := map[string]struct {
105+
version CephVersionName
106+
expected string
107+
}{
108+
"quincy": {
109+
version: CephVersionNameQuincy,
110+
expected: `"quincy"`,
111+
},
112+
"reef": {
113+
version: CephVersionNameReef,
114+
expected: `"reef"`,
115+
},
116+
"squid": {
117+
version: CephVersionNameSquid,
118+
expected: `"squid"`,
119+
},
120+
"unknown": {
121+
version: CephVersionNameUnknown,
122+
expected: `"unknown"`,
123+
},
124+
}
125+
126+
for name, test := range tests {
127+
t.Run(name, func(t *testing.T) {
128+
t.Parallel()
129+
130+
result, err := json.Marshal(test.version)
131+
require.NoError(t, err)
132+
require.Equal(t, test.expected, string(result))
133+
})
134+
}
135+
}
136+
137+
func TestCephVersionNameUnmarshalJSON(t *testing.T) {
138+
t.Parallel()
139+
140+
tests := map[string]struct {
141+
input string
142+
expected CephVersionName
143+
expectError bool
144+
}{
145+
"quincy": {
146+
input: `"quincy"`,
147+
expected: CephVersionNameQuincy,
148+
},
149+
"reef": {
150+
input: `"reef"`,
151+
expected: CephVersionNameReef,
152+
},
153+
"squid": {
154+
input: `"squid"`,
155+
expected: CephVersionNameSquid,
156+
},
157+
"invalid": {
158+
input: `"invalid"`,
159+
expectError: true,
160+
},
161+
"malformed json": {
162+
input: `quincy`,
163+
expectError: true,
164+
},
165+
}
166+
167+
for name, test := range tests {
168+
t.Run(name, func(t *testing.T) {
169+
t.Parallel()
170+
171+
var result CephVersionName
172+
err := json.Unmarshal([]byte(test.input), &result)
173+
174+
if test.expectError {
175+
require.Error(t, err)
176+
} else {
177+
require.NoError(t, err)
178+
require.Equal(t, test.expected, result)
179+
}
180+
})
181+
}
182+
}

0 commit comments

Comments
 (0)