From 7c10ff958e57d02d13287c4cdbe0aca3781e1600 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 9 Jan 2025 16:18:06 -0600 Subject: [PATCH] test unique insert failure --- example/main.go | 24 ++++++++++++++++++++++-- newsort.go | 15 +-------------- sort.go | 4 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/example/main.go b/example/main.go index 47dad4f..6222701 100644 --- a/example/main.go +++ b/example/main.go @@ -3,7 +3,11 @@ package main -import "go.wit.com/log" +import ( + "os" + + "go.wit.com/log" +) // sent via -ldflags var VERSION string @@ -17,5 +21,21 @@ var pb *Fruits func main() { pb = NewFruits() - log.Info("did nothing yet", pb) + + fruit := &Fruit{ + Brand: "mom", + City: "New NewYork", + } + if pb.AppendUnique(fruit) { + log.Info("AppendUnique() ok") + } else { + log.Info("AppendUnique() failed") + os.Exit(-1) + } + if pb.AppendUnique(fruit) { + log.Info("AppendUnique() worked but should not have") + os.Exit(-1) + } else { + log.Info("AppendUnique() failed ok") + } } diff --git a/newsort.go b/newsort.go index 8a4925b..863bb2e 100644 --- a/newsort.go +++ b/newsort.go @@ -21,21 +21,8 @@ func (pb *Files) makeNewSortfile(pf *File) error { pf.Base.iterTop(f) pf.Base.iterNext(f) + pf.appendUnique(f) // Append() enforce no unique keys - /* - for _, msg := range pf.MsgNames { - if msg.DoMutex { - for _, key := range msg.Sort { - pf.iterTop(f, key) - pf.iterNext(f, key) - } - } else { - log.Info("Skipping syncLock() for", msg.Name, "DoMutex = false") - } - } - */ - - pf.appendUnique(f, nil, sortmap) // Append() enforce no unique keys return nil // iterSortAll(f, sortmap) diff --git a/sort.go b/sort.go index d60ebb8..1c3ac9a 100644 --- a/sort.go +++ b/sort.go @@ -185,9 +185,9 @@ func iterEnd(w io.Writer, names map[string]string) { func iterAppend(w io.Writer, names map[string]string) { } -func (pf *File) appendUnique(w io.Writer, blah *MsgName, names map[string]string) { +func (pf *File) appendUnique(w io.Writer) { var MSG string = pf.Bases.Name - var BASE string = names["Base"] + var BASE string = pf.Base.Name var LOCK string = pf.Bases.Lockname if argv.Mutex {