From 83fd8b7e54df88ed3edad434633590204efc5cfb Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 6 Nov 2024 19:40:59 -0500 Subject: [PATCH] engine: util: Add more cmp utility functions --- engine/util/cmp.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/engine/util/cmp.go b/engine/util/cmp.go index a529545b12..f2e0d79bf8 100644 --- a/engine/util/cmp.go +++ b/engine/util/cmp.go @@ -33,6 +33,20 @@ import ( "fmt" ) +// StrPtrCmp compares two pointers to strings. If they aren't both nil or aren't +// both of the same value, then this errors. +func StrPtrCmp(x, y *string) error { + if (x == nil) != (y == nil) { // xor + return fmt.Errorf("the Content differs") + } + if x != nil && y != nil { + if *x != *y { // compare the strings + return fmt.Errorf("the contents of ptr differ") + } + } + return nil +} + // StrListCmp compares two lists of strings. If they are not the same length or // do not contain identical strings in the same order, then this errors. func StrListCmp(x, y []string) error {