mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #123254 from liggitt/revert-copy-test
Revert "kubeadm: increase ut coverage for app/util"
This commit is contained in:
commit
c93c53ce24
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
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 (
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCopyFile(t *testing.T) {
|
|
||||||
tmpdir, err := os.MkdirTemp("", "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Failed to create temporary directory")
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err = os.RemoveAll(tmpdir)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Failed to remove temporary directory")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
tmpfile, err := os.CreateTemp(tmpdir, "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to create temporary file")
|
|
||||||
}
|
|
||||||
restrictedFile, err := os.CreateTemp(tmpdir, "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Failed to create temporary restricted file")
|
|
||||||
}
|
|
||||||
err = restrictedFile.Chmod(0000)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Failed to change file mode")
|
|
||||||
}
|
|
||||||
|
|
||||||
type args struct {
|
|
||||||
src string
|
|
||||||
dest string
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
wantErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "src file does not exist",
|
|
||||||
args: args{
|
|
||||||
src: "foo",
|
|
||||||
dest: tmpdir + "bar",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "src file exists",
|
|
||||||
args: args{
|
|
||||||
src: tmpfile.Name(),
|
|
||||||
dest: tmpdir + "bar",
|
|
||||||
},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "src file cannot be read or written",
|
|
||||||
args: args{
|
|
||||||
src: restrictedFile.Name(),
|
|
||||||
dest: tmpdir + "bar",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
if err := CopyFile(tt.args.src, tt.args.dest); (err != nil) != tt.wantErr {
|
|
||||||
t.Errorf("CopyFile() error = %v, wantErr %v", err, tt.wantErr)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -431,35 +431,3 @@ func TestGroupVersionKindsHasResetConfiguration(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGroupVersionKindsHasClusterConfiguration(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
gvks []schema.GroupVersionKind
|
|
||||||
expected bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "does not have ClusterConfiguraiton",
|
|
||||||
gvks: []schema.GroupVersionKind{
|
|
||||||
{Group: "foo.k8s.io", Version: "v1", Kind: "Foo"},
|
|
||||||
},
|
|
||||||
expected: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has ClusterConfiguraiton",
|
|
||||||
gvks: []schema.GroupVersionKind{
|
|
||||||
{Group: "foo.k8s.io", Version: "v1", Kind: "Foo"},
|
|
||||||
{Group: "foo.k8s.io", Version: "v1", Kind: "ClusterConfiguration"},
|
|
||||||
},
|
|
||||||
expected: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, rt := range tests {
|
|
||||||
t.Run(rt.name, func(t *testing.T) {
|
|
||||||
actual := GroupVersionKindsHasClusterConfiguration(rt.gvks...)
|
|
||||||
if rt.expected != actual {
|
|
||||||
t.Errorf("expected gvks to have a ClusterConfiguration: %t\n\tactual: %t\n", rt.expected, actual)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user