procutils_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 procutils
  15. import (
  16. "os"
  17. "testing"
  18. )
  19. func TestStat(t *testing.T) {
  20. cases := []struct {
  21. filename string
  22. exists bool
  23. isdir bool
  24. }{
  25. {
  26. filename: "/",
  27. exists: true,
  28. isdir: true,
  29. },
  30. {
  31. filename: "/tmp/__0_1_2_3_a_b_c_d____",
  32. exists: false,
  33. isdir: false,
  34. },
  35. }
  36. for _, c := range cases {
  37. fi, err := RemoteStat(c.filename)
  38. if err != nil {
  39. if !c.exists && os.IsNotExist(err) {
  40. // ok
  41. } else {
  42. t.Errorf("expect exists: %v err: %s", c.exists, err)
  43. }
  44. } else {
  45. if fi.IsDir() != c.isdir {
  46. t.Errorf("isdir want: %v got: %v", c.isdir, fi.IsDir())
  47. }
  48. }
  49. }
  50. }