|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package sources |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | +) |
| 20 | + |
| 21 | +func TestNormalizeValue(t *testing.T) { |
| 22 | + // Test case 1: UUID OID (2950) with [16]byte |
| 23 | + uuidBytes := [16]byte{1, 158, 103, 138, 45, 22, 120, 229, 146, 32, 191, 118, 245, 114, 247, 50} |
| 24 | + expectedUUIDStr := "019e678a-2d16-78e5-9220-bf76f572f732" |
| 25 | + |
| 26 | + result := NormalizeValue(uuidBytes, 2950) |
| 27 | + if str, ok := result.(string); !ok || str != expectedUUIDStr { |
| 28 | + t.Errorf("Expected UUID string %s, got %v", expectedUUIDStr, result) |
| 29 | + } |
| 30 | + |
| 31 | + // Test case 2: UUID OID (2950) with other type |
| 32 | + result = NormalizeValue("not-bytes", 2950) |
| 33 | + if str, ok := result.(string); !ok || str != "not-bytes" { |
| 34 | + t.Errorf("Expected original string 'not-bytes', got %v", result) |
| 35 | + } |
| 36 | + |
| 37 | + // Test case 3: Other OID |
| 38 | + result = NormalizeValue(uuidBytes, 1000) |
| 39 | + if bytes, ok := result.([16]byte); !ok || bytes != uuidBytes { |
| 40 | + t.Errorf("Expected original [16]byte array, got %v", result) |
| 41 | + } |
| 42 | + |
| 43 | + // Test case 4: UUID Array OID (2951) with [][16]byte |
| 44 | + uuidArray := [][16]byte{uuidBytes} |
| 45 | + result = NormalizeValue(uuidArray, 2951) |
| 46 | + if arr, ok := result.([]string); !ok || len(arr) != 1 || arr[0] != expectedUUIDStr { |
| 47 | + t.Errorf("Expected []string with %s, got %v", expectedUUIDStr, result) |
| 48 | + } |
| 49 | + |
| 50 | + // Test case 5: UUID Array OID (2951) with []any |
| 51 | + uuidAnyArray := []any{uuidBytes, "not-a-uuid"} |
| 52 | + result = NormalizeValue(uuidAnyArray, 2951) |
| 53 | + if arr, ok := result.([]any); !ok || len(arr) != 2 || arr[0] != expectedUUIDStr || arr[1] != "not-a-uuid" { |
| 54 | + t.Errorf("Expected []any with normalized UUID, got %v", result) |
| 55 | + } |
| 56 | +} |
0 commit comments