remote_readdir_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. "testing"
  17. )
  18. func TestReadDir(t *testing.T) {
  19. files, err := RemoteReadDir(".")
  20. if err != nil {
  21. t.Errorf("RemoteReadDIr %s", err)
  22. } else {
  23. for _, f := range files {
  24. t.Logf("%s %d %v %s", f.Name(), f.Size(), f.IsDir(), f.ModTime())
  25. }
  26. }
  27. }
  28. func TestParseLsLine(t *testing.T) {
  29. cases := []string{
  30. "dr-x------. 45 0 0 16384 2022-04-26 19:48:03.811985235 +0800 .",
  31. "drwxr-xr-x. 26 0 0 4096 2022-04-20 10:06:16.339991488 +0800 ..",
  32. "drwxr-xr-x. 2 0 0 4096 2022-04-01 14:20:53.293839273 +0800 0401",
  33. "drwxr-xr-x. 2 0 0 4096 2022-04-05 15:39:23.634908120 +0800 0405image",
  34. "-rw-r--r--. 1 0 0 335 2022-01-10 09:12:34.924898855 +0800 1.c",
  35. "-rw-r--r--. 1 0 0 304 2022-03-04 11:10:00.803987595 +0800 2.c",
  36. "drwx------. 4 0 0 4096 2021-12-08 11:08:04.304950170 +0800 .ansible",
  37. "-rw-r--r--. 1 0 0 26115746 2022-03-22 19:00:45.368976212 +0800 apigateway-ee-200200321.tgz",
  38. "lrwxrwxrwx. 1 0 0 7 2021-12-16 10:19:58.924982587 +0800 .bash_profile -> .bashrc",
  39. "-rw-------. 1 0 0 4107 2022-04-18 17:26:56.108984702 +0800 .bashrc",
  40. "drwx------. 2 0 0 4096 2021-12-20 20:02:30.483709077 +0800 build",
  41. }
  42. for _, c := range cases {
  43. f, err := parseLsLine(c)
  44. if err != nil {
  45. t.Errorf("parseLsLine %s fail %s", c, err)
  46. } else {
  47. t.Logf("%s %d %v %s", f.Name(), f.Size(), f.IsDir(), f.ModTime())
  48. }
  49. }
  50. }