-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,243 additions
and
298 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2022 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
f, err := os.CreateTemp("", "example-") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
// 输出临时文件的文件名 | ||
fmt.Println("Created temp file:", f.Name()) | ||
defer os.Remove(f.Name()) | ||
|
||
os.Setenv("CONFIGMAP_PATH", f.Name()) | ||
|
||
kubefile, err := os.CreateTemp("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer kubefile.Close() | ||
_, err = kubefile.WriteString("apiVersion: v1\nclusters:\n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2dQazFkNWh3R2k5WTgxU0Nzb2YybitURldyeWNHCkFZOEhBc045M0RyUSt0ZUxWK1QzZ0xpd3BxNEp6QzFLTE1IZ3lDcU1uQXhRYjVkUUN6cFVLNjhaTG1NaVNvVnUKZnd1VTd5WjJyZmtJUUU2MVdsRW03NHQ2VjhkOFpQaVNFTXdTUDlzcE43Q0FHTHNJcElKREg5bEZtYXhjNnNDdwp4UjNUOXhqakE0SjFqSmY5RFdpQWZNWkRFMXhEREd5blZKZGdzeHRiMlFUMHVuRjRTYXZsaDB6alg2NmhrRkErCnhJd0hkWHMrbStTbi9ReWd4YkJKeXB5K0FlNkhZQU0rWE1BUnJtdXlzeHc3SFF4d2ZXM3FsSHVibThDK3JiUEwKcEJRPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==\n server: https://10.6.1.21:6443\n name: kubernetes\ncontexts:\n- context:\n cluster: kubernetes\n user: kubernetes-admin\n name: kubernetes-admin@kubernetes\ncurrent-context: kubernetes-admin@kubernetes\nkind: Config\npreferences: {}\nusers:\n- name: kubernetes-admin\n user:\n client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJRkxqUkdDa0FndlV3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TXpBM01USXdPRE0yTlRWYUZ3MHlOREEzTVRFd09ETTJOVGRhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXdDWW1TQVZDNkxncnBXcFYKdUlWank4U0IrQWN0N0VKVmMyMWZXQzVUUlZhMUJ1eXk2aFNiQlhWWldTN0VZM1JySHZXWWlabkhOdmswRXdjKwptMEIzTzM1dFR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dwovaWVYVkpoajJEemJZSDZHRUtGaUttS1QzbW14WlNBY3B4OGJUYVhlT0IrK3hhdHlMaTJuTWZrPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(kubefile.Name()) | ||
|
||
os.Setenv("KUBECONFIG", kubefile.Name()) | ||
|
||
cfg, err := LoadConfig(false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
cfg.PrintPrettyConfig() | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package controller | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
) | ||
|
||
func TestNamespacePredicate(t *testing.T) { | ||
p := nsPredicate{} | ||
if !p.Create(event.CreateEvent{}) { | ||
t.Fatal("got false") | ||
} | ||
|
||
if !p.Delete(event.DeleteEvent{}) { | ||
t.Fatal("got false") | ||
} | ||
|
||
if !p.Update(event.UpdateEvent{ | ||
ObjectOld: &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "default", | ||
Labels: map[string]string{ | ||
"aa": "bb", | ||
}, | ||
}, | ||
}, | ||
ObjectNew: &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "default", | ||
Labels: map[string]string{ | ||
"aa": "cc", | ||
}, | ||
}, | ||
}, | ||
}) { | ||
t.Fatal("got false") | ||
} | ||
} |
This file contains 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
Oops, something went wrong.