Skip to content

Increase unit test coverage #39136

@constanca-m

Description

@constanca-m

Component(s)

pkg/translator/azurelogs

Describe the issue you're reporting

This is an issue that should ideally be done before #39119, if both would move forward.

Currently, some of the unit tests only check a few fields to see if the extraction was successful. Example:

func TestAppServiceConsoleLog(t *testing.T) {
logs, err := loadJSONLogsAndApplySemanticConventions("log-appserviceconsolelogs.json")
assert.NoError(t, err)
record := logs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().Map().AsRaw()
assert.Equal(t, "CONTAINER_ID", record["container.id"])
assert.Equal(t, "HOST", record["host.id"])
}

Instead, we could follow a similar approach to what AWS Logs encoding extension does. By using files, we can compare that everything in the logs matches what is expected a bit like this:

logs, err := unmarshalerCW.UnmarshalLogs(test.record)
if test.expectedErr != "" {
require.ErrorContains(t, err, test.expectedErr)
return
}
require.NoError(t, err)
expectedLogs, err := golden.ReadLogs(filepath.Join(filesDirectory, test.logsExpectedFilename))
require.NoError(t, err)
require.NoError(t, plogtest.CompareLogs(expectedLogs, logs))

This way we can ensure that any changes done to the code will not affect results, instead of checking that just a few fields won't be changed.

If this change is approved, I volunteer to make these changes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions