Changes to header validation method

This commit is contained in:
J Sen Ooi 2023-12-19 00:21:30 +08:00
parent 0d4dc2cc12
commit 703e3283e4

View file

@ -92,17 +92,33 @@ func serializeLocation[T ~[]string](location T) string {
// Ooi J Sen
// Function to validate headers
func validateHeaders(expected, actual []string) bool {
if len(expected) != len(actual) {
return false
actualHeaderCount := make(map[string]int)
// Count occurrences of headers in the actual slice
for _, header := range actual {
actualHeaderCount[header]++
}
for i := range expected {
if expected[i] != actual[i] {
// Check if all actual headers are within the expected headers
for header, count := range actualHeaderCount {
if count > 0 && !contains(expected, header) {
return false
}
}
return true
}
// Function to check if a string slice contains a specific string
func contains(slice []string, str string) bool {
for _, s := range slice {
if s == str {
return true
}
}
return false
}
// CsvImport imports items from a CSV file. using the standard defined format.
//
// CsvImport applies the following rules/operations