File: read_closer_with_metrics_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (83 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package readcloserwithmetrics

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/aws/middleware/private/metrics"
	"github.com/aws/aws-sdk-go-v2/aws/middleware/private/metrics/testutils"
	"io"
	"testing"
)

func TestNew(t *testing.T) {

	ctx := context.TODO()
	ctx = metrics.InitMetricContext(ctx, &metrics.SharedConnectionCounter{}, &testutils.NoopPublisher{})
	mctx := metrics.Context(ctx)

	expectedData := "testString"
	trc := testutils.TestReadCloser{Data: []byte(expectedData)}

	reader := New(mctx, &trc)
	readData, _ := io.ReadAll(reader)
	actualData := string(readData)

	if actualData != expectedData {
		t.Errorf("Unexpected Data, should be '%s' but was '%s'", expectedData, actualData)
	}
}

func TestReadCloserWithMetrics_Close(t *testing.T) {

	mdrp := &testutils.MetricDataRecorderPublisher{}
	ctx := context.TODO()
	ctx = metrics.InitMetricContext(ctx, &metrics.SharedConnectionCounter{}, mdrp)
	mctx := metrics.Context(ctx)

	expectedData := "testString"
	trc := testutils.TestReadCloser{Data: []byte(expectedData)}

	reader := New(mctx, &trc)

	err := reader.Close()

	if err != nil {
		t.Errorf("Unexpected Error in Close")
	}

	if mdrp.Data == nil {
		t.Errorf("Data should be set in publisher")
	}

	rb := mdrp.Data.Stream.ReadBytes
	if mdrp.Data.Stream.ReadBytes != 0 {
		t.Errorf("Unexpected ReadBytes, should be '%d' but was '%d'", 0, rb)
	}

}

func TestReadCloserWithMetrics_Read(t *testing.T) {
	mdrp := &testutils.MetricDataRecorderPublisher{}
	ctx := context.TODO()
	ctx = metrics.InitMetricContext(ctx, &metrics.SharedConnectionCounter{}, mdrp)
	mctx := metrics.Context(ctx)

	expectedData := "testString"
	trc := testutils.TestReadCloser{Data: []byte(expectedData)}

	reader := New(mctx, &trc)

	err := reader.Close()

	if err != nil {
		t.Errorf("Unexpected Error in Close")
	}

	if mdrp.Data == nil {
		t.Errorf("Data should be set in publisher")
	}

	rb := mdrp.Data.Stream.ReadBytes
	if mdrp.Data.Stream.ReadBytes != 0 {
		t.Errorf("Unexpected ReadBytes, should be '%d' but was '%d'", 0, rb)
	}
}