hostfiles_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 hostinfo
  15. import (
  16. "testing"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. api "yunion.io/x/onecloud/pkg/apis/compute"
  19. )
  20. func TestFixTelegrafConfPath(t *testing.T) {
  21. cases := []struct {
  22. hostFile api.SHostFile
  23. path string
  24. }{
  25. {
  26. hostFile: api.SHostFile{
  27. SInfrasResourceBase: apis.SInfrasResourceBase{
  28. SDomainLevelResourceBase: apis.SDomainLevelResourceBase{
  29. SStandaloneResourceBase: apis.SStandaloneResourceBase{
  30. Name: "mysql1",
  31. },
  32. },
  33. },
  34. Type: string(api.TelegrafConf),
  35. Path: "/etc/telegraf/mysqlmon.conf",
  36. },
  37. path: "/etc/telegraf/telegraf.d/mysqlmon.conf",
  38. },
  39. {
  40. hostFile: api.SHostFile{
  41. SInfrasResourceBase: apis.SInfrasResourceBase{
  42. SDomainLevelResourceBase: apis.SDomainLevelResourceBase{
  43. SStandaloneResourceBase: apis.SStandaloneResourceBase{
  44. Name: "mysql2",
  45. },
  46. },
  47. },
  48. Type: string(api.TelegrafConf),
  49. },
  50. path: "/etc/telegraf/telegraf.d/mysql2.conf",
  51. },
  52. }
  53. for _, c := range cases {
  54. fixed := fixTelegrafConfPath(&c.hostFile)
  55. if fixed.Path != c.path {
  56. t.Errorf("fixTelegrafConfPath(%s) = %s, expected %s", c.hostFile.Name, fixed.Path, c.path)
  57. }
  58. }
  59. }