From e444d0f0f6834161aea4c8b017813074b33edc6d Mon Sep 17 00:00:00 2001 From: Aleksandr Tolstikhin Date: Fri, 5 Apr 2024 14:28:05 +0700 Subject: [PATCH 1/3] Coverage default.go --- config/default_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/config/default_test.go b/config/default_test.go index d790fb5f..de104c2a 100644 --- a/config/default_test.go +++ b/config/default_test.go @@ -31,6 +31,9 @@ func (c *cfg) Validate() error { if c.IntValue != 10 { return fmt.Errorf("invalid IntValue %d != %d", 10, c.IntValue) } + if c.MapValue["key1"] != true { + return fmt.Errorf("invalid MapValue %t != %t", true, c.MapValue["key1"]) + } return nil } @@ -105,3 +108,19 @@ func TestValidate(t *testing.T) { t.Fatal(err) } } + +func TestString(t *testing.T) { + cfg := config.NewConfig() + res := cfg.String() + if res != "default" { + t.Fatalf("string value invalid: %s", res) + } +} + +func TestName(t *testing.T) { + cfg := config.NewConfig() + res := cfg.Name() + if res != "" { + t.Fatal("name value not empty") + } +} -- 2.45.2 From f8e97545c18e4454405d38f749c1059d650e7807 Mon Sep 17 00:00:00 2001 From: Aleksandr Tolstikhin Date: Fri, 13 Sep 2024 00:23:54 +0700 Subject: [PATCH 2/3] Add flow/flow_test --- flow/flow_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 flow/flow_test.go diff --git a/flow/flow_test.go b/flow/flow_test.go new file mode 100644 index 00000000..a31ba67e --- /dev/null +++ b/flow/flow_test.go @@ -0,0 +1,37 @@ +package flow + +import ( + "reflect" + "testing" +) + +func TestMarshall(t *testing.T) { + a := "json" + res := []byte(a) + m := RawMessage(a) + + b, err := m.MarshalJSON() + if err != nil { + t.Errorf("Error %s", err) + } + + if !reflect.DeepEqual(b, res) { + t.Errorf("Error %s", err) + } + +} + +func TestUnmarshall(t *testing.T) { + strn := "json" + b := []byte(strn) + // exp := string(b) + m := RawMessage(b) + + if err := m.UnmarshalJSON(b); err != nil { + t.Errorf("Error %s", m) + } + + if string(m) != strn { + t.Errorf("Error %s", m) + } +} -- 2.45.2 From 26e1267f6cb31c459267f117020289cc2c106763 Mon Sep 17 00:00:00 2001 From: Aleksandr Tolstikhin Date: Sat, 14 Sep 2024 00:49:33 +0700 Subject: [PATCH 3/3] Update flow_test.go --- flow/flow_test.go | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/flow/flow_test.go b/flow/flow_test.go index a31ba67e..3adcdfff 100644 --- a/flow/flow_test.go +++ b/flow/flow_test.go @@ -5,33 +5,32 @@ import ( "testing" ) -func TestMarshall(t *testing.T) { - a := "json" - res := []byte(a) - m := RawMessage(a) +func FuzzMarshall(f *testing.F) { + f.Fuzz(func(t *testing.T, ref []byte) { + rm := RawMessage(ref) - b, err := m.MarshalJSON() - if err != nil { - t.Errorf("Error %s", err) - } - - if !reflect.DeepEqual(b, res) { - t.Errorf("Error %s", err) - } + b, err := rm.MarshalJSON() + if err != nil { + t.Errorf("Error MarshalJSON: %s", err) + } + if !reflect.DeepEqual(ref, b) { + t.Errorf("Error. Expected '%s', was '%s'", ref, b) + } + }) } -func TestUnmarshall(t *testing.T) { - strn := "json" - b := []byte(strn) - // exp := string(b) - m := RawMessage(b) +func FuzzUnmarshall(f *testing.F) { + f.Fuzz(func(t *testing.T, ref string) { + b := []byte(ref) + rm := RawMessage(b) - if err := m.UnmarshalJSON(b); err != nil { - t.Errorf("Error %s", m) - } + if err := rm.UnmarshalJSON(b); err != nil { + t.Errorf("Error UnmarshalJSON: %s", err) + } - if string(m) != strn { - t.Errorf("Error %s", m) - } + if ref != string(rm) { + t.Errorf("Error. Expected '%s', was '%s'", ref, rm) + } + }) } -- 2.45.2