file_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "testing"
  17. . "github.com/smartystreets/goconvey/convey"
  18. )
  19. func TestIsFile(t *testing.T) {
  20. if !IsFile("file.go") {
  21. t.Errorf("IsExist:\n Expect => %v\n Got => %v\n", true, false)
  22. }
  23. if IsFile("testdata") {
  24. t.Errorf("IsExist:\n Expect => %v\n Got => %v\n", false, true)
  25. }
  26. if IsFile("files.go") {
  27. t.Errorf("IsExist:\n Expect => %v\n Got => %v\n", false, true)
  28. }
  29. }
  30. func TestIsExist(t *testing.T) {
  31. Convey("Check if file or directory exists", t, func() {
  32. Convey("Pass a file name that exists", func() {
  33. So(IsExist("file.go"), ShouldEqual, true)
  34. })
  35. Convey("Pass a directory name that exists", func() {
  36. So(IsExist("testdata"), ShouldEqual, true)
  37. })
  38. Convey("Pass a directory name that does not exist", func() {
  39. So(IsExist(".hg"), ShouldEqual, false)
  40. })
  41. })
  42. }
  43. func BenchmarkIsFile(b *testing.B) {
  44. for i := 0; i < b.N; i++ {
  45. IsFile("file.go")
  46. }
  47. }
  48. func BenchmarkIsExist(b *testing.B) {
  49. for i := 0; i < b.N; i++ {
  50. IsExist("file.go")
  51. }
  52. }