Skip to content

Commit 5d3cf10

Browse files
committed
add unit tests for params command
1 parent 036a9ef commit 5d3cf10

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

x/dkim/client/cli/cli_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,45 @@ func TestGenerateDkimPublicKey(t *testing.T) {
211211
}()
212212
}
213213

214+
func TestGetParams(t *testing.T) {
215+
cmd := cli.GetParams()
216+
require.NotNil(t, cmd)
217+
require.Equal(t, "params", cmd.Use)
218+
require.Equal(t, "Query DKIM module parameters", cmd.Short)
219+
require.NotEmpty(t, cmd.Long)
220+
require.NotEmpty(t, cmd.Example)
221+
222+
// Test that command has RunE function defined
223+
require.NotNil(t, cmd.RunE)
224+
225+
// Test command structure
226+
require.NotNil(t, cmd.Flags())
227+
228+
// Test args validation - params takes no args (cobra.NoArgs)
229+
t.Run("args validator with 0 args", func(t *testing.T) {
230+
err := cmd.Args(cmd, []string{})
231+
require.NoError(t, err, "should accept no args")
232+
})
233+
234+
t.Run("args validator with 1 arg should fail", func(t *testing.T) {
235+
err := cmd.Args(cmd, []string{"extra"})
236+
require.Error(t, err, "should reject any args")
237+
})
238+
239+
t.Run("args validator with 2 args should fail", func(t *testing.T) {
240+
err := cmd.Args(cmd, []string{"arg1", "arg2"})
241+
require.Error(t, err, "should reject any args")
242+
})
243+
244+
// Call RunE to ensure coverage - expect panic/error without context
245+
func() {
246+
defer func() {
247+
_ = recover() // Ignore panics from missing context
248+
}()
249+
_ = cmd.RunE(cmd, []string{})
250+
}()
251+
}
252+
214253
func TestGenerateDkimPubKeyMsg(t *testing.T) {
215254
t.Run("with invalid domain/selector (DNS lookup fails)", func(t *testing.T) {
216255
// Testing with a domain that won't have DKIM records
@@ -945,6 +984,24 @@ func TestGetQueryCmdIncludesGenerateDkim(t *testing.T) {
945984
require.Contains(t, generateCmd.Aliases, "gdkim")
946985
}
947986

987+
func TestGetQueryCmdIncludesParams(t *testing.T) {
988+
queryCmd := cli.GetQueryCmd()
989+
990+
// Find the params subcommand
991+
var paramsCmd *cobra.Command
992+
for _, subCmd := range queryCmd.Commands() {
993+
if subCmd.Use == "params" {
994+
paramsCmd = subCmd
995+
break
996+
}
997+
}
998+
999+
require.NotNil(t, paramsCmd, "params should be a subcommand of query")
1000+
require.Equal(t, "Query DKIM module parameters", paramsCmd.Short)
1001+
require.NotEmpty(t, paramsCmd.Long)
1002+
require.NotEmpty(t, paramsCmd.Example)
1003+
}
1004+
9481005
func TestGenerateDkimPublicKeyInQueryCmdTree(t *testing.T) {
9491006
queryCmd := cli.GetQueryCmd()
9501007

0 commit comments

Comments
 (0)