-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwidget_test.go
More file actions
43 lines (37 loc) · 755 Bytes
/
Copy pathwidget_test.go
File metadata and controls
43 lines (37 loc) · 755 Bytes
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
package widget_test
import (
"sync"
"testing"
"github.com/bitfield/widget"
)
func TestCreateGivesNoErrorForValidWidget(t *testing.T) {
s := newMapStore()
w := widget.Widget{
ID: "widget01",
Name: "Acme Giant Rubber Band",
}
wantID := "widget01"
gotID, err := widget.Create(s, w)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if wantID != gotID {
t.Errorf("want %q, got %q", wantID, gotID)
}
}
type mapStore struct {
m *sync.Mutex
data map[string]widget.Widget
}
func newMapStore() *mapStore {
return &mapStore{
m: new(sync.Mutex),
data: map[string]widget.Widget{},
}
}
func (ms *mapStore) Store(w widget.Widget) (string, error) {
ms.m.Lock()
defer ms.m.Unlock()
ms.data[w.ID] = w
return w.ID, nil
}