Skip to content

Commit a2f18a1

Browse files
committed
ACLP Logs destination - fix unit tests
Signed-off-by: sjerecze <sjerecze@akamai.com>
1 parent 5d3d3f7 commit a2f18a1

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

linode/monitorlogsdestination/framework_models.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,29 @@ func (m *LogsDestinationDataSourceModel) ParseLogsDestination(dest *linodego.Log
225225
flat := &LogsDestinationFlatDetailsModel{}
226226
d := dest.Details
227227

228-
flat.AccessKeyID = types.StringValue(d.AccessKeyID)
229-
flat.BucketName = types.StringValue(d.BucketName)
230-
flat.Host = types.StringValue(d.Host)
231-
flat.Path = types.StringValue(d.Path)
232-
flat.EndpointURL = types.StringValue(d.EndpointURL)
233-
flat.ContentType = types.StringValue(d.ContentType)
234-
flat.DataCompression = types.StringValue(d.DataCompression)
235-
236-
if d.Authentication != nil {
228+
stringOrNull := func(s string) types.String {
229+
if s == "" {
230+
return types.StringNull()
231+
}
232+
return types.StringValue(s)
233+
}
234+
235+
flat.AccessKeyID = stringOrNull(d.AccessKeyID)
236+
flat.BucketName = stringOrNull(d.BucketName)
237+
flat.Host = stringOrNull(d.Host)
238+
flat.Path = stringOrNull(d.Path)
239+
flat.EndpointURL = stringOrNull(d.EndpointURL)
240+
flat.ContentType = stringOrNull(d.ContentType)
241+
flat.DataCompression = stringOrNull(d.DataCompression)
242+
243+
// Handle nested structs gracefully
244+
flat.AuthenticationType = types.StringNull()
245+
if d.Authentication != nil && d.Authentication.Type != "" {
237246
flat.AuthenticationType = types.StringValue(string(d.Authentication.Type))
238247
}
239-
if d.ClientCertificateDetails != nil {
248+
249+
flat.TLSHostname = types.StringNull()
250+
if d.ClientCertificateDetails != nil && d.ClientCertificateDetails.TLSHostname != "" {
240251
flat.TLSHostname = types.StringValue(d.ClientCertificateDetails.TLSHostname)
241252
}
242253

linode/monitorlogsdestination/framework_models_unit_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ func TestParseLogsDestination_DataSource(t *testing.T) {
183183
assert.Equal(t, types.Int64Value(2), m.Version)
184184

185185
assert.NotNil(t, m.Details)
186-
assert.Equal(t, "DSKEY", m.Details.AccessKeyID)
187-
assert.Equal(t, "ds-bucket", m.Details.BucketName)
188-
assert.Equal(t, "eu-central-1.linodeobjects.com", m.Details.Host)
189-
assert.Equal(t, "/ds-logs", m.Details.Path)
186+
assert.Equal(t, types.StringValue("DSKEY"), m.Details.AccessKeyID)
187+
assert.Equal(t, types.StringValue("ds-bucket"), m.Details.BucketName)
188+
assert.Equal(t, types.StringValue("eu-central-1.linodeobjects.com"), m.Details.Host)
189+
assert.Equal(t, types.StringValue("/ds-logs"), m.Details.Path)
190190
}
191191

192192
func TestParseLogsDestination_DataSource_CustomHTTPS(t *testing.T) {
@@ -228,14 +228,14 @@ func TestParseLogsDestination_DataSource_CustomHTTPS(t *testing.T) {
228228
assert.Equal(t, types.Int64Value(3), m.Version)
229229

230230
assert.NotNil(t, m.Details)
231-
assert.Equal(t, "https://logs.example.com/ingest", m.Details.EndpointURL)
232-
assert.Equal(t, "application/json", m.Details.ContentType)
233-
assert.Equal(t, "gzip", m.Details.DataCompression)
234-
assert.Equal(t, "basic", m.Details.AuthenticationType)
235-
assert.Equal(t, "logs.example.com", m.Details.TLSHostname)
231+
assert.Equal(t, types.StringValue("https://logs.example.com/ingest"), m.Details.EndpointURL)
232+
assert.Equal(t, types.StringValue("application/json"), m.Details.ContentType)
233+
assert.Equal(t, types.StringValue("gzip"), m.Details.DataCompression)
234+
assert.Equal(t, types.StringValue("basic"), m.Details.AuthenticationType)
235+
assert.Equal(t, types.StringValue("logs.example.com"), m.Details.TLSHostname)
236236

237237
// OBJ storage fields must be empty for a custom_https destination.
238-
assert.Empty(t, m.Details.AccessKeyID)
239-
assert.Empty(t, m.Details.BucketName)
240-
assert.Empty(t, m.Details.Host)
238+
assert.True(t, m.Details.AccessKeyID.IsNull())
239+
assert.True(t, m.Details.BucketName.IsNull())
240+
assert.True(t, m.Details.Host.IsNull())
241241
}

0 commit comments

Comments
 (0)