-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KATC] Add snake case row transform step (#1765)
- Loading branch information
1 parent
d678648
commit ec8bef7
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package katc | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
|
||
"github.com/serenize/snaker" | ||
) | ||
|
||
func camelToSnake(_ context.Context, _ *slog.Logger, row map[string][]byte) (map[string][]byte, error) { | ||
snakeCaseRow := make(map[string][]byte) | ||
for k, v := range row { | ||
snakeCaseKey := snaker.CamelToSnake(k) | ||
snakeCaseRow[snakeCaseKey] = v | ||
} | ||
|
||
return snakeCaseRow, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package katc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/kolide/launcher/pkg/log/multislogger" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_camelToSnake(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, tt := range []struct { | ||
testCaseName string | ||
input string | ||
expectedOutput string | ||
}{ | ||
{ | ||
testCaseName: "basic camelcase column name", | ||
input: "emailAddress", | ||
expectedOutput: "email_address", | ||
}, | ||
{ | ||
testCaseName: "already snake case", | ||
input: "email_address", | ||
expectedOutput: "email_address", | ||
}, | ||
} { | ||
tt := tt | ||
t.Run(tt.testCaseName, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
outputRows, err := camelToSnake(context.TODO(), multislogger.NewNopLogger(), map[string][]byte{ | ||
tt.input: nil, | ||
}) | ||
require.NoError(t, err) | ||
require.Contains(t, outputRows, tt.expectedOutput) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters