Skip to content

Commit 85cb6a5

Browse files
authored
Merge pull request #4066 from camilamacedo86/cleanup-tests
🌱 (cleanup): cleanup tests for plugin/util functions
2 parents 0164fb6 + bfba6d8 commit 85cb6a5

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

pkg/plugin/util/suite_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package util
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
func TestStage(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "Utils Suite")
29+
}

pkg/plugin/util/testdata/exampleFile.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/plugin/util/util_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ import (
2323

2424
var _ = Describe("InsertCode", Ordered, func() {
2525
path := filepath.Join("testdata", "exampleFile.txt")
26-
var originalContent []byte
26+
var content []byte
2727

2828
BeforeAll(func() {
29-
var err error
30-
originalContent, err = os.ReadFile(path)
29+
err := os.MkdirAll("testdata", 0755)
30+
Expect(err).NotTo(HaveOccurred())
31+
32+
if _, err := os.Stat(path); os.IsNotExist(err) {
33+
err = os.WriteFile(path, []byte("exampleTarget"), 0644)
34+
Expect(err).NotTo(HaveOccurred())
35+
}
36+
37+
content, err = os.ReadFile(path)
3138
Expect(err).NotTo(HaveOccurred())
3239
})
3340

3441
AfterAll(func() {
35-
err := os.WriteFile(path, originalContent, 0644)
42+
err := os.WriteFile(path, content, 0644)
43+
Expect(err).NotTo(HaveOccurred())
44+
45+
err = os.RemoveAll("testdata")
3646
Expect(err).NotTo(HaveOccurred())
3747
})
3848

0 commit comments

Comments
 (0)