MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestModule_ProvideCommand_initCmd

Function TestModule_ProvideCommand_initCmd

config/module_test.go:62–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestModule_ProvideCommand_initCmd(t *testing.T) {
63 cases := []struct {
64 name string
65 output string
66 args []string
67 expected string
68 }{
69 {
70 "foo yaml",
71 "./testdata/module_test.yaml",
72 []string{"config", "init", "foo", "--outputFile", "./testdata/module_test.yaml"},
73 "./testdata/module_test_foo_expected.yaml",
74 },
75
76 {
77 "old yaml",
78 "./testdata/module_test.yaml",
79 []string{"config", "init", "--outputFile", "./testdata/module_test.yaml"},
80 "./testdata/module_test_expected.yaml",
81 },
82 {
83 "foo json",
84 "./testdata/module_test.json",
85 []string{"config", "init", "foo", "--outputFile", "./testdata/module_test.json", "--style", "json"},
86 "./testdata/module_test_foo_expected.json",
87 },
88 {
89 "old json",
90 "./testdata/module_test.json",
91 []string{"config", "init", "--outputFile", "./testdata/module_test.json", "--style", "json"},
92 "./testdata/module_test_expected.json",
93 },
94 {
95 "partial json",
96 "./testdata/module_test_partial.json",
97 []string{"config", "init", "--outputFile", "./testdata/module_test_partial.json", "--style", "json"},
98 "./testdata/module_test_partial_expected.json",
99 },
100 {
101 "partial yaml",
102 "./testdata/module_test_partial.yaml",
103 []string{"config", "init", "baz", "--outputFile", "./testdata/module_test_partial.yaml"},
104 "./testdata/module_test_partial_expected.yaml",
105 },
106 }
107 for _, c := range cases {
108 t.Run(c.name, func(t *testing.T) {
109 rootCmd := setup()
110 defer tearDown()
111 rootCmd.SetArgs(c.args)
112 rootCmd.Execute()
113 testTarget, _ := ioutil.ReadFile(c.output)
114 expected, _ := ioutil.ReadFile(c.expected)
115 expectedString := string(expected)
116 if runtime.GOOS == "windows" {
117 expectedString = strings.ReplaceAll(expectedString, "\r", "")
118 }
119 assert.Equal(t, expectedString, string(testTarget))

Callers

nothing calls this directly

Calls 3

setupFunction · 0.85
tearDownFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected