-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.go
72 lines (60 loc) · 1.54 KB
/
app_test.go
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
package exporter_test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/rafalmnich/exporter"
"github.com/rafalmnich/exporter/mocks"
"github.com/rafalmnich/exporter/sink"
"github.com/rafalmnich/exporter/tests"
)
func TestNewApplication(t *testing.T) {
imp := new(mocks.Importer)
exp := new(mocks.Exporter)
_, db := tests.MockGormDB()
app := exporter.NewApplication(imp, exp, db)
assert.Implements(t, (*exporter.Application)(nil), app)
}
func TestApp_Import(t *testing.T) {
imp := new(mocks.Importer)
exp := new(mocks.Exporter)
expected := []*sink.Reading{
{
Name: "name",
Type: sink.Input,
Value: 20,
Occurred: time.Now(),
},
}
ctx := context.Background()
imp.On("Import", ctx).Return(expected, nil)
app := exporter.NewApplication(imp, exp, nil)
data, err := app.Import(context.Background())
assert.NoError(t, err)
assert.Equal(t, expected, data)
}
func TestApp_Export(t *testing.T) {
imp := new(mocks.Importer)
exp := new(mocks.Exporter)
importData := []*sink.Reading{
{
Name: "name",
Type: sink.Input,
Value: 10,
Occurred: time.Now(),
},
}
ctx := context.Background()
exp.On("Export", ctx, importData).Return(nil)
app := exporter.NewApplication(imp, exp, nil)
err := app.Export(context.Background(), importData)
assert.NoError(t, err)
}
func TestApp_IsHealthy(t *testing.T) {
imp := new(mocks.Importer)
exp := new(mocks.Exporter)
_, db := tests.MockGormDB()
app := exporter.NewApplication(imp, exp, db)
assert.NoError(t, app.IsHealthy())
}