Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksanford committed Nov 18, 2024
1 parent 9bcc78d commit 0199242
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions data/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ import (
)

var (
dummyTime = time.Date(2024, time.January, 10, 23, 0, 0, 0, time.UTC)
structCapturer = CaptureFunc(func(ctx context.Context, _ map[string]*anypb.Any) (CaptureResult, error) {
return dummyStructReading, nil
})
binaryCapturer = CaptureFunc(func(ctx context.Context, _ map[string]*anypb.Any) (CaptureResult, error) {
return CaptureResult{
Timestamps: Timestamps{
TimeRequested: dummyTime,
TimeReceived: dummyTime.Add(time.Second),
},
Type: CaptureTypeBinary,
Binaries: []Binary{{Payload: dummyBytesReading}},
}, nil
})
dummyStructReading = CaptureResult{
Timestamps: Timestamps{
TimeRequested: dummyTime,
TimeReceived: dummyTime.Add(time.Second),
},
Type: CaptureTypeTabular,
TabularData: TabularData{dummyStructReadingProto},
}
Expand All @@ -50,13 +59,24 @@ func TestNewCollector(t *testing.T) {

// If not missing parameters, should not return an error.
c2, err2 := NewCollector(nil, CollectorParams{
DataType: CaptureTypeTabular,
ComponentName: "name",
Logger: logging.NewTestLogger(t),
Target: NewCaptureBuffer("dir", nil, 50),
})

test.That(t, c2, test.ShouldNotBeNil)
test.That(t, err2, test.ShouldBeNil)
test.That(t, c2, test.ShouldNotBeNil)

c3, err3 := NewCollector(nil, CollectorParams{
DataType: CaptureTypeBinary,
ComponentName: "name",
Logger: logging.NewTestLogger(t),
Target: NewCaptureBuffer("dir", nil, 50),
})

test.That(t, err3, test.ShouldBeNil)
test.That(t, c3, test.ShouldNotBeNil)
}

// Test that the Collector correctly writes the SensorData on an interval.
Expand Down Expand Up @@ -290,6 +310,7 @@ func TestLogErrorsOnlyOnce(t *testing.T) {
mockClock := clock.NewMock()

params := CollectorParams{
DataType: CaptureTypeTabular,
ComponentName: "testComponent",
Interval: interval,
MethodParams: map[string]*anypb.Any{"name": fakeVal},
Expand Down Expand Up @@ -327,10 +348,10 @@ func validateReadings(t *testing.T, act []*v1.SensorData, n int) {
}
}

//nolint
func getAllFiles(dir string) []os.FileInfo {
var files []os.FileInfo
_ = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
//nolint:nilerr
if err != nil {
return nil
}
Expand Down

0 comments on commit 0199242

Please sign in to comment.