path_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2021 EMQ Technologies Co., Ltd.
  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 conf
  15. import (
  16. "strings"
  17. "testing"
  18. "github.com/stretchr/testify/require"
  19. )
  20. func TestAbsolutePath(t *testing.T) {
  21. tests := []struct {
  22. r string
  23. a string
  24. }{
  25. {
  26. r: "etc/services",
  27. a: "/etc/kuiper/services",
  28. }, {
  29. r: "data/",
  30. a: "/var/lib/kuiper/data/",
  31. }, {
  32. r: logDir,
  33. a: "/var/log/kuiper",
  34. }, {
  35. r: "plugins",
  36. a: "/var/lib/kuiper/plugins",
  37. },
  38. }
  39. for i, tt := range tests {
  40. aa, err := absolutePath(tt.r)
  41. if err != nil {
  42. t.Errorf("error: %v", err)
  43. } else {
  44. if !(tt.a == aa) {
  45. t.Errorf("%d result mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.a, aa)
  46. }
  47. }
  48. }
  49. }
  50. func TestGetDataLoc_Funcs(t *testing.T) {
  51. d, err := GetDataLoc()
  52. if err != nil {
  53. t.Errorf("Errors when getting data loc: %s.", err)
  54. } else if !strings.HasSuffix(d, "kuiper/data/test") {
  55. t.Errorf("Unexpected data location %s", d)
  56. }
  57. }
  58. func TestPathConfig(t *testing.T) {
  59. PathConfig.Dirs["etc"] = "/etc/kuiper"
  60. PathConfig.Dirs["data"] = "/data/kuiper"
  61. PathConfig.Dirs["log"] = "/log/kuiper"
  62. PathConfig.Dirs["plugins"] = "/tmp/plugins"
  63. testcases := []struct {
  64. dir string
  65. expect string
  66. }{
  67. {
  68. dir: etcDir,
  69. expect: "/etc/kuiper",
  70. },
  71. {
  72. dir: dataDir,
  73. expect: "/data/kuiper",
  74. },
  75. {
  76. dir: logDir,
  77. expect: "/log/kuiper",
  78. },
  79. {
  80. dir: pluginsDir,
  81. expect: "/tmp/plugins",
  82. },
  83. {
  84. dir: "etc/source",
  85. expect: "/etc/kuiper/source",
  86. },
  87. }
  88. for _, tc := range testcases {
  89. d, err := absolutePath(tc.dir)
  90. require.NoError(t, err)
  91. require.Equal(t, tc.expect, d)
  92. }
  93. }