Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Skandalik committed Oct 14, 2024
1 parent 97686ad commit d138c78
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gdpr/protect_device_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const (

// ProtectDeviceID hides last two character from passed device id and returns string with protected value
func ProtectDeviceID(val string) string {
lowered := strings.ToLower(val)
if val == "" {
return val
}

if val == "" || lowered == unknownValue || lowered == nonAvailableValue {
lowered := strings.ToLower(val)
if lowered == unknownValue || lowered == nonAvailableValue {
return val
}

Expand Down
45 changes: 45 additions & 0 deletions gdpr/protect_device_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,48 @@ func BenchmarkProtectDeviceID(b *testing.B) {
ProtectDeviceID(strconv.Itoa(i))
}
}

func BenchmarkProtectDeviceID_Empty(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("")
}
}

func BenchmarkProtectDeviceID_NA_Mixed(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("N/a")
}
}

func BenchmarkProtectDeviceID_NA_Lower(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("n/a")
}
}

func BenchmarkProtectDeviceID_Unknown_Mixed(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("Unknown")
}
}

func BenchmarkProtectDeviceID_Unknown_Lower(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
ProtectDeviceID("unknown")
}
}

0 comments on commit d138c78

Please sign in to comment.