path_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. )
  19. func TestAbsolutePath(t *testing.T) {
  20. var tests = []struct {
  21. r string
  22. a string
  23. }{
  24. {
  25. r: "etc/services",
  26. a: "/etc/kuiper/services",
  27. }, {
  28. r: "data/",
  29. a: "/var/lib/kuiper/data/",
  30. }, {
  31. r: logDir,
  32. a: "/var/log/kuiper",
  33. }, {
  34. r: "plugins",
  35. a: "/var/lib/kuiper/plugins",
  36. },
  37. }
  38. for i, tt := range tests {
  39. aa, err := absolutePath(tt.r)
  40. if err != nil {
  41. t.Errorf("error: %v", err)
  42. } else {
  43. if !(tt.a == aa) {
  44. t.Errorf("%d result mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.a, aa)
  45. }
  46. }
  47. }
  48. }
  49. func TestGetDataLoc_Funcs(t *testing.T) {
  50. d, err := GetDataLoc()
  51. if err != nil {
  52. t.Errorf("Errors when getting data loc: %s.", err)
  53. } else if !strings.HasSuffix(d, "kuiper/data/test") {
  54. t.Errorf("Unexpected data location %s", d)
  55. }
  56. }