add test for kinflate
This commit is contained in:
parent
bf2ba35a03
commit
e3ca383a35
|
@ -17,22 +17,25 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/kubectl/pkg/kinflate"
|
||||
)
|
||||
|
||||
// TestableMain allows test coverage for main.
|
||||
func TestableMain() error {
|
||||
fmt.Println("Hello world.")
|
||||
return nil
|
||||
func TestableMain(out, errOut io.Writer, cmdMungeFn func(*cobra.Command)) error {
|
||||
cmd := kinflate.NewCmdKinflate(out, errOut)
|
||||
if cmdMungeFn != nil {
|
||||
cmdMungeFn(cmd)
|
||||
}
|
||||
return cmd.Execute()
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestableMain()
|
||||
cmd := kinflate.NewCmdKinflate(os.Stdout, os.Stderr)
|
||||
err := cmd.Execute()
|
||||
err := TestableMain(os.Stdout, os.Stderr, nil)
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -17,16 +17,41 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// TODO: real tests
|
||||
// e.g. make an inmemory file system, put yaml in there, inflate it
|
||||
// to a buffer, compare to expected results, etc.
|
||||
// a script in there, have script write file
|
||||
func TestTrueMain(t *testing.T) {
|
||||
err := TestableMain()
|
||||
const updateEnvVar = "UPDATE_KINFLATE_EXPECTED_DATA"
|
||||
updateKinflateExpected := os.Getenv(updateEnvVar) == "true"
|
||||
|
||||
input := "testdata/simple/in/instances/exampleinstance/"
|
||||
expected := "testdata/simple/out/expected.yaml"
|
||||
cmdMungeFn := func(cmd *cobra.Command) {
|
||||
cmd.Flags().Set("filename", input)
|
||||
}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
err := TestableMain(buf, os.Stderr, cmdMungeFn)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
actualBytes := buf.Bytes()
|
||||
if !updateKinflateExpected {
|
||||
expectedBytes, err := ioutil.ReadFile(expected)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(actualBytes, expectedBytes) {
|
||||
t.Errorf("%s\ndoesn't equal expected:\n%s\n", actualBytes, expectedBytes)
|
||||
}
|
||||
} else {
|
||||
ioutil.WriteFile(expected, actualBytes, 0644)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../../../../../pkg/kinflate/examples/simple/instances
|
|
@ -0,0 +1 @@
|
|||
../../../../../pkg/kinflate/examples/simple/package
|
|
@ -0,0 +1,120 @@
|
|||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
app-init.ini: |
|
||||
FOO=bar
|
||||
BAR=baz
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-config-ht8ck65bcg
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
DB_PASSWORD: somepw
|
||||
DB_USERNAME: admin
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-env-hf26mf2f2f
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUIwekNDQVgyZ0F3SUJBZ0lKQUkvTTdCWWp3Qit1TUEwR0NTcUdTSWIzRFFFQk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NEcKNk9CMU0xV08rayt6dG5YLzFTdk5lV3U4RDZHSW10dXBMVFlnalpjSHVmeWtqMDlqaUhtakh4OHU4WlpCL28xTgpNUUloQVBXK2V5Wm83YXkzbE16MVYwMVdWak5LSzlRU24xTUpsYjA2aC9MdVl2OUZBaUVBMjVXUGVkS2dWeUNXClNtVXdiUHc4Zm5UY3BxRFdFM3lUTzN2S2NlYnFNU3NDSUJGM1VtVnVlOFlVM2p5YkMzTnh1WHEzd05tMzRSOFQKeFZMSHdEWGgvNk5KQWlFQWwyb0hHR0x6NjRCdUFmaktycXd6N3FNWXI5SENMSWUvWXNvV3Evb2x6U2NDSVFEaQpEMmxXdXNvZTIvbkVxZkRWVldHV2x5Sjd5T21xYVZtL2lOVU45QjJOMmc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
|
||||
kind: Secret
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-tls-4d47hbbh9m
|
||||
type: kubernetes.io/tls
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-mungebot-service
|
||||
spec:
|
||||
ports:
|
||||
- port: 7002
|
||||
selector:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
note: This is a test annotation
|
||||
labels:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-mungebot
|
||||
spec:
|
||||
replicas: 2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mungebot
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: FOO
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
key: somekey
|
||||
name: test-infra-app-env-hf26mf2f2f
|
||||
- name: BAR
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: somekey
|
||||
name: test-infra-app-tls-4d47hbbh9m
|
||||
- name: foo
|
||||
value: bar
|
||||
image: nginx:1.7.9
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
- envFrom:
|
||||
- configMapRef:
|
||||
name: test-infra-app-env-hf26mf2f2f
|
||||
- secretRef:
|
||||
name: test-infra-app-tls-4d47hbbh9m
|
||||
image: busybox
|
||||
name: busybox
|
||||
volumeMounts:
|
||||
- mountPath: /tmp/env
|
||||
name: app-env
|
||||
- mountPath: /tmp/tls
|
||||
name: app-tls
|
||||
volumes:
|
||||
- configMap:
|
||||
name: test-infra-app-env-hf26mf2f2f
|
||||
name: app-env
|
||||
- name: app-tls
|
||||
secret:
|
||||
name: test-infra-app-tls-4d47hbbh9m
|
Loading…
Reference in New Issue