github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/read_only_calls_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package apiserver 5 6 import ( 7 "strings" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/apiserver/common" 13 ) 14 15 type readOnlyCallsSuite struct { 16 } 17 18 var _ = gc.Suite(&readOnlyCallsSuite{}) 19 20 func (*readOnlyCallsSuite) TestReadOnlyCallsExist(c *gc.C) { 21 // Iterate through the list of readOnlyCalls and make sure 22 // that the facades are reachable. 23 facades := common.Facades.List() 24 25 maxVersion := map[string]int{} 26 for _, facade := range facades { 27 version := 0 28 for _, ver := range facade.Versions { 29 if ver > version { 30 version = ver 31 } 32 } 33 maxVersion[facade.Name] = version 34 } 35 36 for _, name := range readOnlyCalls.Values() { 37 parts := strings.Split(name, ".") 38 facade, method := parts[0], parts[1] 39 version := maxVersion[facade] 40 41 _, _, err := lookupMethod(facade, version, method) 42 c.Check(err, jc.ErrorIsNil) 43 } 44 } 45 46 func (*readOnlyCallsSuite) TestReadOnlyCall(c *gc.C) { 47 for _, test := range []struct { 48 facade string 49 method string 50 }{ 51 {"Action", "Actions"}, 52 {"Client", "FullStatus"}, 53 {"Service", "Get"}, 54 {"Storage", "ListStorageDetails"}, 55 } { 56 c.Logf("check %s.%s", test.facade, test.method) 57 c.Check(isCallReadOnly(test.facade, test.method), jc.IsTrue) 58 } 59 } 60 61 func (*readOnlyCallsSuite) TestWritableCalls(c *gc.C) { 62 for _, test := range []struct { 63 facade string 64 method string 65 }{ 66 {"Client", "UnknownMethod"}, 67 {"Service", "Deploy"}, 68 {"UnknownFacade", "List"}, 69 } { 70 c.Logf("check %s.%s", test.facade, test.method) 71 c.Check(isCallReadOnly(test.facade, test.method), jc.IsFalse) 72 } 73 }