Skip to content

Commit ef50138

Browse files
committed
handle key not in fixtures map edge case
1 parent 327c1f4 commit ef50138

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

internal/fixtures/fixtures.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,59 +151,66 @@ func NewFixture(db DBInterface) Fixtures {
151151
}
152152

153153
func (f *Fixtures) GetNamespaceKey(key string) FixtureDataNamespace {
154-
if fixtureData.Namespaces.Data[key].Id == "" {
154+
ns, ok := fixtureData.Namespaces.Data[key]
155+
if !ok || ns.Id == "" {
155156
slog.Error("could not find namespace", slog.String("id", key))
156-
panic("could not find namespace")
157+
panic("could not find namespace fixture: " + key)
157158
}
158-
return fixtureData.Namespaces.Data[key]
159+
return ns
159160
}
160161

161162
func (f *Fixtures) GetAttributeKey(key string) FixtureDataAttribute {
162-
if fixtureData.Attributes.Data[key].Id == "" {
163+
a, ok := fixtureData.Attributes.Data[key]
164+
if !ok || a.Id == "" {
163165
slog.Error("could not find attributes", slog.String("id", key))
164-
panic("could not find attributes")
166+
panic("could not find attribute fixture: " + key)
165167
}
166-
return fixtureData.Attributes.Data[key]
168+
return a
167169
}
168170

169171
func (f *Fixtures) GetAttributeValueKey(key string) FixtureDataAttributeValue {
170-
if fixtureData.AttributeValues.Data[key].Id == "" {
172+
av, ok := fixtureData.AttributeValues.Data[key]
173+
if !ok || av.Id == "" {
171174
slog.Error("could not find attribute-values", slog.String("id", key))
172-
panic("could not find attribute-values")
175+
panic("could not find attribute-value fixture: " + key)
173176
}
174-
return fixtureData.AttributeValues.Data[key]
177+
return av
175178
}
176179

177180
func (f *Fixtures) GetSubjectMappingKey(key string) FixtureDataSubjectMapping {
178-
if fixtureData.SubjectMappings.Data[key].Id == "" {
181+
sm, ok := fixtureData.SubjectMappings.Data[key]
182+
if !ok || sm.Id == "" {
179183
slog.Error("could not find subject-mappings", slog.String("id", key))
180-
panic("could not find subject-mappings")
184+
panic("could not find subject-mapping fixture: " + key)
181185
}
182-
return fixtureData.SubjectMappings.Data[key]
186+
return sm
183187
}
184188

185189
func (f *Fixtures) GetSubjectConditionSetKey(key string) SubjectConditionSet {
186-
if fixtureData.SubjectConditionSet.Data[key].Id == "" {
190+
scs, ok := fixtureData.SubjectConditionSet.Data[key]
191+
if !ok || scs.Id == "" {
187192
slog.Error("could not find subject-condition-set", slog.String("id", key))
188-
panic("could not find subject-condition-set")
193+
panic("could not find subject-condition-set fixture: " + key)
189194
}
190-
return fixtureData.SubjectConditionSet.Data[key]
195+
return scs
191196
}
192197

193198
func (f *Fixtures) GetResourceMappingKey(key string) FixtureDataResourceMapping {
194-
if fixtureData.ResourceMappings.Data[key].Id == "" {
199+
rm, ok := fixtureData.ResourceMappings.Data[key]
200+
if !ok || rm.Id == "" {
195201
slog.Error("could not find resource-mappings", slog.String("id", key))
196-
panic("could not find resource-mappings")
202+
panic("could not find resource-mapping fixture: " + key)
197203
}
198-
return fixtureData.ResourceMappings.Data[key]
204+
return rm
199205
}
200206

201207
func (f *Fixtures) GetKasRegistryKey(key string) FixtureDataKasRegistry {
202-
if fixtureData.KasRegistries.Data[key].Id == "" {
208+
kasr, ok := fixtureData.KasRegistries.Data[key]
209+
if !ok || kasr.Id == "" {
203210
slog.Error("could not find kas-registry", slog.String("id", key))
204-
panic("could not find kas-registry")
211+
panic("could not find kas-registry fixture: " + key)
205212
}
206-
return fixtureData.KasRegistries.Data[key]
213+
return kasr
207214
}
208215

209216
func (f *Fixtures) Provision() {

0 commit comments

Comments
 (0)