-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test and setup command show and attach config command
Test reading and writing to the output file Signed-off-by: Luke Mallon (Nalum) <[email protected]>
- Loading branch information
Showing
3 changed files
with
130 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2023 Stefan Prodan | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var showModCmd = &cobra.Command{ | ||
Use: "show", | ||
Short: "Commands for showing module information", | ||
} | ||
|
||
func init() { | ||
modCmd.AddCommand(showModCmd) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2023 Stefan Prodan | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func Test_ShowConfig(t *testing.T) { | ||
modPath := "testdata/module" | ||
|
||
g := NewWithT(t) | ||
|
||
// Push the module to registry | ||
output, err := executeCommand(fmt.Sprintf( | ||
"mod show config %s", | ||
modPath, | ||
)) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
|
||
g.Expect(output).To(ContainSubstring("`client: enabled:`")) | ||
g.Expect(output).To(ContainSubstring("`client: image: repository:`")) | ||
g.Expect(output).To(ContainSubstring("`server: enabled:`")) | ||
} | ||
|
||
func Test_ShowConfigOutput(t *testing.T) { | ||
modPath := "testdata/module" | ||
|
||
g := NewWithT(t) | ||
|
||
// Push the module to registry | ||
_, err := executeCommand(fmt.Sprintf( | ||
"mod show config %s --output %s/README.md", | ||
modPath, | ||
modPath, | ||
)) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
|
||
rmFile, err := os.ReadFile(fmt.Sprintf("%s/README.md", modPath)) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
|
||
strContent := string(rmFile) | ||
|
||
g.Expect(strContent).To(ContainSubstring("`client: enabled:`")) | ||
g.Expect(strContent).To(ContainSubstring("`client: image: repository:`")) | ||
g.Expect(strContent).To(ContainSubstring("`server: enabled:`")) | ||
|
||
err = os.Remove(fmt.Sprintf("%s/README.md", modPath)) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
} |