mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Test writing configurations with numeric names
This commit is contained in:
parent
be4683ef9c
commit
1f2feb2e7e
@ -18,6 +18,7 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/clientcmd/api:go_default_library",
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package clientcmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -29,6 +30,7 @@ import (
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest"
|
||||
)
|
||||
@ -175,6 +177,56 @@ func TestConflictingCurrentContext(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeYAML(t *testing.T) {
|
||||
config := clientcmdapi.Config{
|
||||
CurrentContext: "any-context-value",
|
||||
Contexts: map[string]*clientcmdapi.Context{
|
||||
"433e40": {
|
||||
Cluster: "433e40",
|
||||
},
|
||||
},
|
||||
Clusters: map[string]*clientcmdapi.Cluster{
|
||||
"0": {
|
||||
Server: "https://localhost:1234",
|
||||
},
|
||||
"1": {
|
||||
Server: "https://localhost:1234",
|
||||
},
|
||||
"433e40": {
|
||||
Server: "https://localhost:1234",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := Write(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := []byte(`apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
server: https://localhost:1234
|
||||
name: "0"
|
||||
- cluster:
|
||||
server: https://localhost:1234
|
||||
name: "1"
|
||||
- cluster:
|
||||
server: https://localhost:1234
|
||||
name: "433e40"
|
||||
contexts:
|
||||
- context:
|
||||
cluster: "433e40"
|
||||
user: ""
|
||||
name: "433e40"
|
||||
current-context: any-context-value
|
||||
kind: Config
|
||||
preferences: {}
|
||||
users: null
|
||||
`)
|
||||
if !bytes.Equal(expected, data) {
|
||||
t.Error(diff.ObjectReflectDiff(string(expected), string(data)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadingEmptyMaps(t *testing.T) {
|
||||
configFile, _ := ioutil.TempFile("", "")
|
||||
defer os.Remove(configFile.Name())
|
||||
|
Loading…
Reference in New Issue
Block a user