Skip to content

Commit

Permalink
Merge pull request #4066 from camilamacedo86/cleanup-tests
Browse files Browse the repository at this point in the history
🌱 (cleanup): cleanup tests for plugin/util functions
  • Loading branch information
k8s-ci-robot authored Aug 11, 2024
2 parents 0164fb6 + bfba6d8 commit 85cb6a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
29 changes: 29 additions & 0 deletions pkg/plugin/util/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package util

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestStage(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Utils Suite")
}
1 change: 0 additions & 1 deletion pkg/plugin/util/testdata/exampleFile.txt

This file was deleted.

18 changes: 14 additions & 4 deletions pkg/plugin/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@ import (

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

BeforeAll(func() {
var err error
originalContent, err = os.ReadFile(path)
err := os.MkdirAll("testdata", 0755)
Expect(err).NotTo(HaveOccurred())

if _, err := os.Stat(path); os.IsNotExist(err) {
err = os.WriteFile(path, []byte("exampleTarget"), 0644)
Expect(err).NotTo(HaveOccurred())
}

content, err = os.ReadFile(path)
Expect(err).NotTo(HaveOccurred())
})

AfterAll(func() {
err := os.WriteFile(path, originalContent, 0644)
err := os.WriteFile(path, content, 0644)
Expect(err).NotTo(HaveOccurred())

err = os.RemoveAll("testdata")
Expect(err).NotTo(HaveOccurred())
})

Expand Down

0 comments on commit 85cb6a5

Please sign in to comment.