MCPcopy
hub / github.com/kptdev/kpt / TestCmd_currentDir

Function TestCmd_currentDir

internal/cmdinit/cmdinit_test.go:89–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestCmd_currentDir(t *testing.T) {
90 d, err := ioutil.TempDir("", "kpt")
91 assert.NoError(t, err)
92 assert.NoError(t, os.Mkdir(filepath.Join(d, "my-pkg"), 0700))
93
94 packageDir := filepath.Join(d, "my-pkg")
95 currentDir, err := os.Getwd()
96 assert.NoError(t, err)
97 err = func() error {
98 nestedErr := os.Chdir(packageDir)
99 if nestedErr != nil {
100 return nestedErr
101 }
102 defer func() {
103 deferErr := os.Chdir(currentDir)
104 if deferErr != nil {
105 panic(deferErr)
106 }
107 }()
108
109 r := cmdinit.NewRunner("kpt")
110 r.Command.SetArgs([]string{".", "--description", "my description", "--tag", "app.kpt.dev/cockroachdb"})
111 return r.Command.Execute()
112 }()
113 assert.NoError(t, err)
114
115 // verify the contents
116 b, err := ioutil.ReadFile(filepath.Join(packageDir, "Kptfile"))
117 assert.NoError(t, err)
118 assert.Equal(t, `apiVersion: kpt.dev/v1alpha1
119kind: Kptfile
120metadata:
121 name: my-pkg
122packageMetadata:
123 tags:
124 - app.kpt.dev/cockroachdb
125 shortDescription: my description
126`, string(b))
127}
128
129// TestCmd_failExists verifies the command throws and error if the directory exists
130func TestCmd_failNotExists(t *testing.T) {

Callers

nothing calls this directly

Calls 1

NewRunnerFunction · 0.92

Tested by

no test coverage detected