use t.Run for tests

This commit is contained in:
Joel Wetzell
2026-02-27 22:30:52 -06:00
parent 0b20f3ffb9
commit eb8c6aba19
26 changed files with 208 additions and 273 deletions
+18 -23
View File
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"strings"
"testing"
@@ -58,19 +57,17 @@ func TestGoodChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeChunk(testCase.bytes)
actual, err := DecodeChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %v\n", testCase.expected)
fmt.Printf("actual: %v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -88,18 +85,16 @@ func TestBadChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
_, err := DecodeChunk(testCase.bytes)
_, err := DecodeChunk(testCase.bytes)
if err == nil {
t.Errorf("Test '%s' should have failed fail to decode chunk properly", testCase.description)
}
if !strings.Contains(err.Error(), testCase.errorShouldContain) {
t.Errorf("Test '%s' did not return the correct error", testCase.description)
fmt.Printf("expected: %v\n", testCase.errorShouldContain)
fmt.Printf("actual: %v\n", err.Error())
}
if err == nil {
t.Error("should have failed fail to decode chunk properly")
}
if !strings.Contains(err.Error(), testCase.errorShouldContain) {
t.Errorf("did not return the correct error expected: %s, got: %s", testCase.errorShouldContain, err.Error())
}
})
}
}
+9 -12
View File
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -155,18 +154,16 @@ func TestGoodDataPacketChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeDataPacketChunk(testCase.bytes)
actual, err := DecodeDataPacketChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
+9 -12
View File
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -111,18 +110,16 @@ func TestGoodDataTrackerChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeDataTrackerChunk(testCase.bytes)
actual, err := DecodeDataTrackerChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -126,18 +125,16 @@ func TestGoodDataTrackerListChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeDataTrackerListChunk(testCase.bytes)
actual, err := DecodeDataTrackerListChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -31,19 +30,17 @@ func TestGoodDataTrackerStatusChunk(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeDataTrackerStatusChunk(testCase.bytes)
actual, err := DecodeDataTrackerStatusChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %v\n", testCase.expected)
fmt.Printf("actual: %v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -32,18 +31,17 @@ func TestGoodDataTrackerTimestampChunk(t *testing.T) {
for _, testCase := range testCases {
actual, err := DecodeDataTrackerTimestampChunk(testCase.bytes)
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeDataTrackerTimestampChunk(testCase.bytes)
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %v\n", testCase.expected)
fmt.Printf("actual: %v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -93,19 +92,17 @@ func TestGoodDataTrackerXYZChunk(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeDataTrackerXYZChunk(testCase.bytes)
actual, err := DecodeDataTrackerXYZChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %v\n", testCase.expected)
fmt.Printf("actual: %v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
+9 -13
View File
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -134,19 +133,16 @@ func TestGoodInfoPacketChunkDecoding(t *testing.T) {
for _, testCase := range testCases {
actual, err := DecodeInfoPacketChunk(testCase.bytes)
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeInfoPacketChunk(testCase.bytes)
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
fmt.Printf("%+v\n", actual.Data.TrackerList)
fmt.Printf("%+v\n", testCase.expected.Data.TrackerList)
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
// fmt.Printf("expected: %+v\n", testCase.expected)
// fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -32,18 +31,16 @@ func TestGoodInfoSystemNameChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeInfoSystemNameChunk(testCase.bytes)
actual, err := DecodeInfoSystemNameChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
+9 -12
View File
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -40,18 +39,16 @@ func TestGoodInfoTrackerChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeInfoTrackerChunk(testCase.bytes)
actual, err := DecodeInfoTrackerChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -50,18 +49,16 @@ func TestGoodInfoTrackerListChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeInfoTrackerListChunk(testCase.bytes)
actual, err := DecodeInfoTrackerListChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -33,17 +32,16 @@ func TestGoodInfoTrackerNameChunkDecoding(t *testing.T) {
for _, testCase := range testCases {
actual, err := DecodeInfoTrackerNameChunk(testCase.bytes)
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodeInfoTrackerNameChunk(testCase.bytes)
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}
+9 -12
View File
@@ -1,7 +1,6 @@
package decoders
import (
"fmt"
"reflect"
"testing"
@@ -36,18 +35,16 @@ func TestGoodPacketHeaderChunkDecoding(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
actual, err := DecodePacketHeaderChunk(testCase.bytes)
actual, err := DecodePacketHeaderChunk(testCase.bytes)
if err != nil {
t.Errorf("failed to decode chunk properly, error: %v", err)
}
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
}
})
}
}