resourcebase_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package db
  15. import (
  16. "testing"
  17. "yunion.io/x/pkg/util/rbacscope"
  18. "yunion.io/x/pkg/utils"
  19. "yunion.io/x/sqlchemy"
  20. "yunion.io/x/onecloud/pkg/mcclient"
  21. "yunion.io/x/onecloud/pkg/util/rbacutils"
  22. )
  23. type omniToken struct {
  24. mcclient.SSimpleToken
  25. }
  26. func (tk *omniToken) IsAllow(scope rbacscope.TRbacScope, service string, resource string, action string, extra ...string) rbacutils.SPolicyResult {
  27. return rbacutils.PolicyAllow
  28. }
  29. func TestListFields(t *testing.T) {
  30. sqlchemy.SetupMockDatabaseBackend()
  31. man := NewResourceBaseManager(
  32. &SResourceBase{},
  33. "tbl",
  34. "keyword",
  35. "keywords",
  36. )
  37. userCred := &omniToken{}
  38. inc, exc := listFields(&man, userCred)
  39. for _, fn := range []string{"deleted", "deleted_at"} {
  40. if !utils.IsInStringArray(fn, inc) {
  41. t.Errorf("resourcebase: field %q not included", fn)
  42. }
  43. if utils.IsInStringArray(fn, exc) {
  44. t.Errorf("resourcebase: field %q excluded", fn)
  45. }
  46. }
  47. }