sharablebase_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. "reflect"
  17. "testing"
  18. )
  19. func TestISharableMergeChangeOwnerCandidateDomainIds(t *testing.T) {
  20. cases := []struct {
  21. candidates [][]string
  22. want []string
  23. }{
  24. {
  25. candidates: [][]string{
  26. nil,
  27. []string{"abc"},
  28. []string{},
  29. []string{"abc", "bcd"},
  30. []string{"bcd"},
  31. },
  32. want: []string{"123"},
  33. },
  34. {
  35. candidates: [][]string{
  36. nil,
  37. []string{},
  38. },
  39. want: nil,
  40. },
  41. }
  42. model := &SInfrasResourceBase{}
  43. model.DomainId = "123"
  44. for _, c := range cases {
  45. got := ISharableMergeChangeOwnerCandidateDomainIds(model, c.candidates...)
  46. if !reflect.DeepEqual(got, c.want) {
  47. t.Errorf("want: %s got %s", c.want, got)
  48. }
  49. }
  50. }
  51. func TestISharableMergeShareRequireDomainIds(t *testing.T) {
  52. cases := []struct {
  53. requires [][]string
  54. want []string
  55. }{
  56. {
  57. requires: [][]string{
  58. nil,
  59. []string{"abc"},
  60. },
  61. want: nil,
  62. },
  63. {
  64. requires: [][]string{
  65. {"abc"},
  66. {"def"},
  67. {"abc", "def"},
  68. },
  69. want: []string{"abc", "def"},
  70. },
  71. }
  72. for _, c := range cases {
  73. got := ISharableMergeShareRequireDomainIds(c.requires...)
  74. if !reflect.DeepEqual(got, c.want) {
  75. t.Errorf("want: %s got %s", c.want, got)
  76. }
  77. }
  78. }