dir_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2013 com authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // 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, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package com
  15. import (
  16. "os"
  17. "testing"
  18. . "github.com/smartystreets/goconvey/convey"
  19. )
  20. func TestIsDir(t *testing.T) {
  21. Convey("Check if given path is a directory", t, func() {
  22. Convey("Pass a file name", func() {
  23. So(IsDir("file.go"), ShouldEqual, false)
  24. })
  25. Convey("Pass a directory name", func() {
  26. So(IsDir("testdata"), ShouldEqual, true)
  27. })
  28. Convey("Pass a invalid path", func() {
  29. So(IsDir("foo"), ShouldEqual, false)
  30. })
  31. })
  32. }
  33. func TestCopyDir(t *testing.T) {
  34. Convey("Items of two slices should be same", t, func() {
  35. s1, err := StatDir("testdata", true)
  36. So(err, ShouldEqual, nil)
  37. err = CopyDir("testdata", "testdata2")
  38. So(err, ShouldEqual, nil)
  39. s2, err := StatDir("testdata2", true)
  40. os.RemoveAll("testdata2")
  41. So(err, ShouldEqual, nil)
  42. So(CompareSliceStr(s1, s2), ShouldEqual, true)
  43. })
  44. }
  45. func BenchmarkIsDir(b *testing.B) {
  46. for i := 0; i < b.N; i++ {
  47. IsDir("file.go")
  48. }
  49. }