MCPcopy
hub / github.com/dropbox/godropbox / TestGetSetAdd

Method TestGetSetAdd

lockstore/map_test.go:22–84  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

20}
21
22func (s *LockingMapSuite) TestGetSetAdd(c *C) {
23 l := NewLockingMap(defaultOptions)
24
25 // Get is empty
26 val, ok := l.Get("test")
27 c.Assert(val, IsNil)
28 c.Assert(ok, Equals, false)
29
30 // Set/Get works
31 l.Set("test", "foo")
32 val, ok = l.Get("test")
33 c.Assert(val, NotNil)
34 c.Assert(ok, Equals, true)
35 c.Assert(val, Equals, "foo")
36
37 // Get test2 empty
38 val, ok = l.Get("test2")
39 c.Assert(val, IsNil)
40 c.Assert(ok, Equals, false)
41
42 // Set test2 works, Get test unchanged
43 l.Set("test", "foo2")
44 val, ok = l.Get("test")
45 c.Assert(val, NotNil)
46 c.Assert(ok, Equals, true)
47 c.Assert(val, Equals, "foo2")
48
49 // Get test2 ok
50 val, ok = l.Get("test2")
51 c.Assert(val, IsNil)
52 c.Assert(ok, Equals, false)
53
54 // Set test2, check in reverse
55 l.Set("test2", "bar")
56 val, ok = l.Get("test2")
57 c.Assert(val, NotNil)
58 c.Assert(ok, Equals, true)
59 c.Assert(val, Equals, "bar")
60 val, ok = l.Get("test")
61 c.Assert(val, NotNil)
62 c.Assert(ok, Equals, true)
63 c.Assert(val, Equals, "foo2")
64
65 // Add over existing should fail
66 ok = l.Add("test", "baz")
67 c.Assert(ok, Equals, false)
68
69 // Get test should be old value pre-add
70 val, ok = l.Get("test")
71 c.Assert(val, NotNil)
72 c.Assert(ok, Equals, true)
73 c.Assert(val, Equals, "foo2")
74
75 // Add new should work
76 ok = l.Add("test3", "baz")
77 c.Assert(ok, Equals, true)
78
79 // Get test3 should be new

Callers

nothing calls this directly

Calls 4

GetMethod · 0.95
SetMethod · 0.95
AddMethod · 0.95
NewLockingMapFunction · 0.70

Tested by

no test coverage detected