Example #1
0
func (*StorageSuite) TestMemStorage(c *gc.C) {
	store := bakery.NewMemStorage()
	err := store.Put("foo", "bar")
	c.Assert(err, gc.IsNil)
	item, err := store.Get("foo")
	c.Assert(err, gc.IsNil)
	c.Assert(item, gc.Equals, "bar")

	err = store.Put("bletch", "blat")
	c.Assert(err, gc.IsNil)
	item, err = store.Get("bletch")
	c.Assert(err, gc.IsNil)
	c.Assert(item, gc.Equals, "blat")

	item, err = store.Get("nothing")
	c.Assert(err, gc.Equals, bakery.ErrNotFound)
	c.Assert(item, gc.Equals, "")

	err = store.Del("bletch")
	c.Assert(err, gc.IsNil)

	item, err = store.Get("bletch")
	c.Assert(err, gc.Equals, bakery.ErrNotFound)
	c.Assert(item, gc.Equals, "")
}
Example #2
0
func (s *suite) SetUpSuite(c *gc.C) {
	key, err := bakery.GenerateKey()
	c.Assert(err, gc.IsNil)
	s.authPublicKey = &key.Public
	s.authEndpoint = serve(c, func(endpoint string) (http.Handler, error) {
		return idservice.New(idservice.Params{
			Users: map[string]*idservice.UserInfo{
				"rog": {
					Password: "******",
				},
				"root": {
					Password: "******",
					Groups: map[string]bool{
						"target-service-users": true,
					},
				},
			},
			Service: bakery.NewServiceParams{
				Location: endpoint,
				Store:    bakery.NewMemStorage(),
				Key:      key,
				Locator:  bakery.NewPublicKeyRing(),
			},
		})
	})
	c.Logf("auth endpoint at %s", s.authEndpoint)
}
Example #3
0
func (*StorageSuite) TestConcurrentMemStorage(c *gc.C) {
	// If locking is not done right, this test will
	// definitely trigger the race detector.
	done := make(chan struct{})
	store := bakery.NewMemStorage()
	for i := 0; i < 3; i++ {
		i := i
		go func() {
			k := fmt.Sprint(i)
			err := store.Put(k, k)
			c.Check(err, gc.IsNil)
			v, err := store.Get(k)
			c.Check(v, gc.Equals, k)
			err = store.Del(k)
			c.Check(err, gc.IsNil)
			done <- struct{}{}
		}()
	}
	for i := 0; i < 3; i++ {
		<-done
	}
}