mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
add example for default view serialization
This commit is contained in:
parent
609208b8b5
commit
06c9dbd32f
@ -18,6 +18,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -47,6 +48,36 @@ type configCommandTest struct {
|
|||||||
expectedOutputs []string
|
expectedOutputs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleView() {
|
||||||
|
expectedConfig := newRedFederalCowHammerConfig()
|
||||||
|
test := configCommandTest{
|
||||||
|
args: []string{"view"},
|
||||||
|
startingConfig: newRedFederalCowHammerConfig(),
|
||||||
|
expectedConfig: expectedConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
output := test.run(nil)
|
||||||
|
fmt.Printf("%v", output)
|
||||||
|
// Output:
|
||||||
|
// apiVersion: v1
|
||||||
|
// clusters:
|
||||||
|
// - cluster:
|
||||||
|
// server: http://cow.org:8080
|
||||||
|
// name: cow-cluster
|
||||||
|
// contexts:
|
||||||
|
// - context:
|
||||||
|
// cluster: cow-cluster
|
||||||
|
// user: red-user
|
||||||
|
// name: federal-context
|
||||||
|
// current-context: ""
|
||||||
|
// kind: Config
|
||||||
|
// preferences: {}
|
||||||
|
// users:
|
||||||
|
// - name: red-user
|
||||||
|
// user:
|
||||||
|
// token: red-token
|
||||||
|
}
|
||||||
|
|
||||||
func TestSetCurrentContext(t *testing.T) {
|
func TestSetCurrentContext(t *testing.T) {
|
||||||
expectedConfig := newRedFederalCowHammerConfig()
|
expectedConfig := newRedFederalCowHammerConfig()
|
||||||
expectedConfig.CurrentContext = "the-new-context"
|
expectedConfig.CurrentContext = "the-new-context"
|
||||||
@ -629,7 +660,7 @@ func testConfigCommand(args []string, startingConfig clientcmdapi.Config) (strin
|
|||||||
return buf.String(), *config
|
return buf.String(), *config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test configCommandTest) run(t *testing.T) {
|
func (test configCommandTest) run(t *testing.T) string {
|
||||||
out, actualConfig := testConfigCommand(test.args, test.startingConfig)
|
out, actualConfig := testConfigCommand(test.args, test.startingConfig)
|
||||||
|
|
||||||
testSetNilMapsToEmpties(reflect.ValueOf(&test.expectedConfig))
|
testSetNilMapsToEmpties(reflect.ValueOf(&test.expectedConfig))
|
||||||
@ -645,6 +676,8 @@ func (test configCommandTest) run(t *testing.T) {
|
|||||||
t.Errorf("expected '%s' in output, got '%s'", expectedOutput, out)
|
t.Errorf("expected '%s' in output, got '%s'", expectedOutput, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
func testSetNilMapsToEmpties(curr reflect.Value) {
|
func testSetNilMapsToEmpties(curr reflect.Value) {
|
||||||
actualCurrValue := curr
|
actualCurrValue := curr
|
||||||
|
Loading…
Reference in New Issue
Block a user