Index: state/apiserver/api_test.go |
=== modified file 'state/apiserver/api_test.go' |
--- state/apiserver/api_test.go 2013-03-20 19:43:36 +0000 |
+++ state/apiserver/api_test.go 2013-03-21 09:32:47 +0000 |
@@ -120,8 +120,8 @@ |
op: opClientGetAnnotations, |
allow: []string{"user-admin", "user-other"}, |
}, { |
- about: "Client.SetAnnotation", |
- op: opClientSetAnnotation, |
+ about: "Client.SetAnnotations", |
+ op: opClientSetAnnotations, |
allow: []string{"user-admin", "user-other"}, |
}, { |
about: "Client.AddServiceUnits", |
@@ -367,13 +367,15 @@ |
return func() {}, nil |
} |
-func opClientSetAnnotation(c *C, st *api.State, mst *state.State) (func(), error) { |
- err := st.Client().SetAnnotation("service-wordpress", "key", "value") |
+func opClientSetAnnotations(c *C, st *api.State, mst *state.State) (func(), error) { |
+ pairs := map[string]string{"key1": "value1", "key2": "value2"} |
+ err := st.Client().SetAnnotations("service-wordpress", pairs) |
if err != nil { |
return func() {}, err |
} |
return func() { |
- st.Client().SetAnnotation("service-wordpress", "key", "") |
+ pairs := map[string]string{"key1": "", "key2": ""} |
+ st.Client().SetAnnotations("service-wordpress", pairs) |
}, nil |
} |
@@ -795,23 +797,17 @@ |
c.Assert(err, IsNil) |
entities := []namedAnnotator{service, unit, machine, environment} |
for i, t := range clientAnnotationsTests { |
- loop: |
for _, entity := range entities { |
id := entity.EntityName() |
c.Logf("test %d. %s. entity %s", i, t.about, id) |
// Set initial entity annotations. |
- for key, value := range t.initial { |
- err := entity.SetAnnotation(key, value) |
- c.Assert(err, IsNil) |
- } |
+ err := entity.SetAnnotations(t.initial) |
+ c.Assert(err, IsNil) |
// Add annotations using the API call. |
- for key, value := range t.input { |
- err := s.APIState.Client().SetAnnotation(id, key, value) |
- if t.err != "" { |
- c.Assert(err, ErrorMatches, t.err) |
- continue loop |
- } |
- c.Assert(err, IsNil) |
+ err = s.APIState.Client().SetAnnotations(id, t.input) |
+ if t.err != "" { |
+ c.Assert(err, ErrorMatches, t.err) |
+ continue |
} |
// Check annotations are correctly set. |
dbann, err := entity.Annotations() |
@@ -823,10 +819,12 @@ |
// Check annotations are correctly returned. |
c.Assert(ann, DeepEquals, dbann) |
// Clean up annotations on the current entity. |
+ cleanup := make(map[string]string) |
for key := range dbann { |
- err = entity.SetAnnotation(key, "") |
- c.Assert(err, IsNil) |
+ cleanup[key] = "" |
} |
+ err = entity.SetAnnotations(cleanup) |
+ c.Assert(err, IsNil) |
} |
} |
} |
@@ -835,7 +833,7 @@ |
bad := []string{"", "machine", "-foo", "foo-", "---", "machine-jim", "unit-123", "unit-foo", "service-", "service-foo/bar"} |
expected := `invalid entity name ".*"` |
for _, id := range bad { |
- err := s.APIState.Client().SetAnnotation(id, "mykey", "myvalue") |
+ err := s.APIState.Client().SetAnnotations(id, map[string]string{"mykey": "myvalue"}) |
c.Assert(err, ErrorMatches, expected) |
_, err = s.APIState.Client().GetAnnotations(id) |
c.Assert(err, ErrorMatches, expected) |