Skip to content

Commit ff28cee

Browse files
committed
Add mocks for the new gio package
1 parent f00e643 commit ff28cee

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

gio/iface_testers.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package gio
2+
3+
import (
4+
"github.com/coyim/gotk3adapter/gioi"
5+
)
6+
7+
func init() {
8+
gioi.AssertGio(&Mock{})
9+
gioi.AssertResource(&MockResource{})
10+
}

gio/mock.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package gio
2+
3+
import (
4+
"github.com/coyim/gotk3adapter/gioi"
5+
"github.com/stretchr/testify/mock"
6+
)
7+
8+
type getter interface {
9+
Get(int) interface{}
10+
}
11+
12+
func ret[T any](args getter, index int) T {
13+
ret, _ := args.Get(index).(T)
14+
return ret
15+
}
16+
17+
type Mock struct {
18+
mock.Mock
19+
}
20+
21+
func (m *Mock) LoadResource(v1 string) (gioi.Resource, error) {
22+
returns := m.Called(v1)
23+
return ret[gioi.Resource](returns, 0), returns.Error(1)
24+
}
25+
26+
func (m *Mock) NewResourceFromData(v1 []byte) (gioi.Resource, error) {
27+
returns := m.Called(v1)
28+
return ret[gioi.Resource](returns, 0), returns.Error(1)
29+
}
30+
31+
func (m *Mock) RegisterResource(v1 gioi.Resource) {
32+
m.Called(v1)
33+
}
34+
35+
func (m *Mock) UnregisterResource(v1 gioi.Resource) {
36+
m.Called(v1)
37+
}

gio/resource.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package gio
2+
3+
import "github.com/stretchr/testify/mock"
4+
5+
type MockResource struct {
6+
mock.Mock
7+
}

0 commit comments

Comments
 (0)