dir_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. _, err := StatDir("testdata", true)
  36. So(err, ShouldEqual, nil)
  37. err = CopyDir("testdata", "testdata2")
  38. So(err, ShouldEqual, nil)
  39. _, err = StatDir("testdata2", true)
  40. os.RemoveAll("testdata2")
  41. So(err, ShouldEqual, nil)
  42. })
  43. }
  44. func BenchmarkIsDir(b *testing.B) {
  45. for i := 0; i < b.N; i++ {
  46. IsDir("file.go")
  47. }
  48. }