(t *testing.T)
| 858 | } |
| 859 | |
| 860 | func TestValidateAttributesUnit(t *testing.T) { |
| 861 | c := &connection{} |
| 862 | |
| 863 | tests := []struct { |
| 864 | name string |
| 865 | attributes map[string]any |
| 866 | expectError bool |
| 867 | errorMsg string |
| 868 | }{ |
| 869 | { |
| 870 | name: "valid attributes", |
| 871 | attributes: map[string]any{ |
| 872 | "valid_key_123": "value", |
| 873 | "another_key": "another value", |
| 874 | "key123": "value123", |
| 875 | "Key_With_Caps": "value", |
| 876 | }, |
| 877 | expectError: false, |
| 878 | }, |
| 879 | { |
| 880 | name: "empty attributes", |
| 881 | attributes: map[string]any{}, |
| 882 | expectError: false, |
| 883 | }, |
| 884 | { |
| 885 | name: "nil attributes", |
| 886 | attributes: nil, |
| 887 | expectError: false, |
| 888 | }, |
| 889 | { |
| 890 | name: "invalid key with hyphen", |
| 891 | attributes: map[string]any{ |
| 892 | "invalid-key": "value", |
| 893 | }, |
| 894 | expectError: true, |
| 895 | errorMsg: "invalid attribute key 'invalid-key': must contain only alphanumeric characters and underscores", |
| 896 | }, |
| 897 | { |
| 898 | name: "invalid key with space", |
| 899 | attributes: map[string]any{ |
| 900 | "invalid key": "value", |
| 901 | }, |
| 902 | expectError: true, |
| 903 | errorMsg: "invalid attribute key 'invalid key': must contain only alphanumeric characters and underscores", |
| 904 | }, |
| 905 | { |
| 906 | name: "invalid key with special characters", |
| 907 | attributes: map[string]any{ |
| 908 | "key@example": "value", |
| 909 | }, |
| 910 | expectError: true, |
| 911 | errorMsg: "invalid attribute key 'key@example': must contain only alphanumeric characters and underscores", |
| 912 | }, |
| 913 | { |
| 914 | name: "empty key", |
| 915 | attributes: map[string]any{ |
| 916 | "": "value", |
| 917 | }, |
nothing calls this directly
no test coverage detected