Created
February 5, 2022 07:32
-
-
Save yujiorama/d11ca02cef8e41fc7eba251310d4e44b to your computer and use it in GitHub Desktop.
file_operation_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"testing" | |
"github.com/sclevine/spec" | |
. "github.com/onsi/gomega" | |
) | |
func testFileOperation(t *testing.T, context spec.G, it spec.S) { | |
var ( | |
Expect = NewWithT(t).Expect | |
path string | |
) | |
it.Before(func() { | |
file, err := os.CreateTemp("", "test.txt") | |
Expect(err).NotTo(HaveOccurred()) | |
defer file.Close() | |
path = file.Name() | |
}) | |
it.After(func() { | |
Expect(os.RemoveAll(path)).To(Succeed()) | |
}) | |
context("when test.txt cannot be opened", func() { | |
it.Before(func() { | |
Expect(os.Chmod(path, 0000)).To(Succeed()) | |
}) | |
it("returns an error", func() { | |
_, err := parser.Parse(path) | |
Expect(err).To(MatchError(ContainSubstring("failed to parse cpanfile.snapshot:"))) | |
Expect(err).To(MatchError(ContainSubstring("permission denied"))) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment