Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update go packages #13

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"log/slog"
"strings"
"testing"
"time"

Expand All @@ -20,7 +19,7 @@ func TestClone(t *testing.T) {
c := masq.NewMasq(masq.WithContain("blue"))

t.Run("string", func(t *testing.T) {
v := gt.MustCast[string](t, c.Redact("blue is blue")).NotNil()
v := gt.Cast[string](t, c.Redact("blue is blue"))
gt.V(t, v).Equal(masq.DefaultRedactMessage)
})

Expand All @@ -41,7 +40,7 @@ func TestClone(t *testing.T) {
Name: "blue",
Label: "five",
}
copied := gt.MustCast[*testData](t, c.Redact(data)).NotNil()
copied := gt.Cast[*testData](t, c.Redact(data))

gt.V(t, copied).NotNil()
gt.Value(t, masq.DefaultRedactMessage).Equal(copied.Name)
Expand All @@ -56,7 +55,7 @@ func TestClone(t *testing.T) {
Name: "blue",
Label: "five",
}
copied := gt.MustCast[testData](t, c.Redact(data)).NotNil()
copied := gt.Cast[testData](t, c.Redact(data))
gt.V(t, copied.Name).Equal(masq.DefaultRedactMessage)
gt.V(t, copied.Label).Equal("five")
})
Expand All @@ -72,7 +71,7 @@ func TestClone(t *testing.T) {
Label: "five",
},
}
copied := gt.MustCast[*testDataParent](t, c.Redact(data)).NotNil()
copied := gt.Cast[*testDataParent](t, c.Redact(data))
gt.V(t, copied.Child.Name).Equal(masq.DefaultRedactMessage)
gt.V(t, copied.Child.Label).Equal("five")
})
Expand All @@ -84,7 +83,7 @@ func TestClone(t *testing.T) {
Label: "five",
},
}
copied := gt.MustCast[map[string]*testData](t, c.Redact(data)).NotNil()
copied := gt.Cast[map[string]*testData](t, c.Redact(data))

gt.V(t, copied["xyz"].Name).Equal(masq.DefaultRedactMessage)
gt.V(t, copied["xyz"].Label).Equal("five")
Expand All @@ -101,7 +100,7 @@ func TestClone(t *testing.T) {
Label: "five",
},
}
copied := gt.MustCast[[]testData](t, c.Redact(data)).NotNil()
copied := gt.Cast[[]testData](t, c.Redact(data))
gt.V(t, copied[0].Name).Equal("orange")
gt.V(t, copied[1].Name).Equal(masq.DefaultRedactMessage)
gt.V(t, copied[1].Label).Equal("five")
Expand All @@ -118,7 +117,7 @@ func TestClone(t *testing.T) {
Label: "five",
},
}
copied := gt.MustCast[[]*testData](t, c.Redact(data)).NotNil()
copied := gt.Cast[[]*testData](t, c.Redact(data))
gt.V(t, copied[0].Name).Equal("orange")
gt.V(t, copied[1].Name).Equal(masq.DefaultRedactMessage)
gt.V(t, copied[1].Label).Equal("five")
Expand All @@ -132,7 +131,7 @@ func TestClone(t *testing.T) {
data := &myData{
Name: "miss blue",
}
copied := gt.MustCast[*myData](t, c.Redact(data)).NotNil()
copied := gt.Cast[*myData](t, c.Redact(data))
gt.V(t, copied.Name).Equal(myType(masq.DefaultRedactMessage))
})

Expand All @@ -146,7 +145,7 @@ func TestClone(t *testing.T) {
unexported: "red",
Exported: "orange",
}
copied := gt.MustCast[*myStruct](t, c.Redact(data)).NotNil()
copied := gt.Cast[*myStruct](t, c.Redact(data))
gt.V(t, copied.unexported).Equal("red")
gt.V(t, copied.Exported).Equal("orange")
})
Expand All @@ -171,7 +170,7 @@ func TestClone(t *testing.T) {
Interface: &struct{}{},
Child: nil,
}
copied := gt.MustCast[*myStruct](t, c.Redact(data)).NotNil()
copied := gt.Cast[*myStruct](t, c.Redact(data))

// function type is not comparable, but it's ok if not nil
gt.V(t, copied.Func).NotNil()
Expand Down Expand Up @@ -215,7 +214,7 @@ func TestClone(t *testing.T) {
ChildPtr: &child{Data: "y"},
}

copied := gt.MustCast[*myStruct](t, mask.Redact(data)).NotNil()
copied := gt.Cast[*myStruct](t, mask.Redact(data))

gt.Value(t, copied.Func).Nil()
gt.Value(t, copied.Chan).Nil()
Expand Down Expand Up @@ -243,7 +242,7 @@ func TestMapData(t *testing.T) {
Label: "five",
},
}
copied := gt.MustCast[map[string]*testData](t, c.Redact(data)).NotNil()
copied := gt.Cast[map[string]*testData](t, c.Redact(data))

gt.V(t, copied["xyz"].Name).Equal(masq.DefaultRedactMessage)
gt.V(t, copied["xyz"].Label).Equal("five")
Expand All @@ -263,7 +262,7 @@ func TestCloneUnexportedPointer(t *testing.T) {
Name: "orange",
},
}
copied := gt.MustCast[*myStruct](t, c.Redact(data)).NotNil()
copied := gt.Cast[*myStruct](t, c.Redact(data))
gt.V(t, copied.c.Name).Equal("orange")
}

Expand All @@ -281,24 +280,24 @@ func TestDoublePointer(t *testing.T) {
data := &myStruct{
c: &childData,
}
copied := gt.MustCast[*myStruct](t, c.Redact(data)).NotNil()
copied := gt.Cast[*myStruct](t, c.Redact(data))
gt.V(t, (*copied.c).Name).Equal("orange")
}

func TestTime(t *testing.T) {
ts := time.Now()
ts := time.Now().UTC()
buf := &bytes.Buffer{}
logger := slog.New(slog.NewJSONHandler(buf, &slog.HandlerOptions{
ReplaceAttr: masq.New(),
}))
logger.Info("hello")

var out map[string]any
gt.Error(t, json.Unmarshal(buf.Bytes(), &out)).Pass()
gt.NoError(t, json.Unmarshal(buf.Bytes(), &out))

tv, ok := out["time"].(string)
gt.B(t, ok).True()
gt.B(t, strings.Contains(tv, ts.Format("2006-01-02"))).True()
gt.S(t, tv).Contains(ts.Format("2006-01-02"))
}

type byteType [4]byte
Expand All @@ -315,5 +314,5 @@ func TestDirectUUID(t *testing.T) {
slog.Any("id", newID),
)

gt.B(t, strings.Contains(buf.String(), "stringer")).True()
gt.S(t, buf.String()).Contains("stringer")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module github.com/m-mizutani/masq

go 1.21

require github.com/m-mizutani/gt v0.0.0-20221229045033-48cc67569435
require github.com/m-mizutani/gt v0.0.7

require github.com/google/go-cmp v0.5.9 // indirect
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/m-mizutani/gt v0.0.0-20221229045033-48cc67569435 h1:4EZ4iNhfccquGCmAAGer708a/mrKKVRWGrErPS2c850=
github.com/m-mizutani/gt v0.0.0-20221229045033-48cc67569435/go.mod h1:0MPYSfGBLmYjTduzADVmIqD58ELQ5IfBFiK/f0FmB3k=
github.com/m-mizutani/gt v0.0.7 h1:wKESp5LWdKpKMySX4Rf05iXYUGtoQ3aI7xOO9VVHAoY=
github.com/m-mizutani/gt v0.0.7/go.mod h1:0MPYSfGBLmYjTduzADVmIqD58ELQ5IfBFiK/f0FmB3k=
Loading