Created
February 5, 2022 07:33
-
-
Save yujiorama/acec2f9987e235692ec6b71a456f4f41 to your computer and use it in GitHub Desktop.
file_operation_test2.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" | |
"runtime" | |
"strings" | |
"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() { | |
if strings.Compare("windows", runtime.GOOS) == 0 { | |
t.SkipNow() | |
} | |
_, 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