-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 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
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 @@ | ||
package dns | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewACommand(t *testing.T) { | ||
cmd := NewACommand() | ||
assert.NotNil(t, cmd) | ||
assert.Equal(t, "A ADDRESS [value] [--command [args...]]", cmd.Use) | ||
assert.Equal(t, []string{"a"}, cmd.Aliases) | ||
} | ||
|
||
func TestACommand_NoArgs(t *testing.T) { | ||
cmd := NewACommand() | ||
err := cmd.Args(cmd, []string{}) | ||
assert.Error(t, err) | ||
assert.Equal(t, "ADDRESS is required argument for the dns command", err.Error()) | ||
} | ||
|
||
func TestACommand_WithArgs(t *testing.T) { | ||
cmd := NewACommand() | ||
err := cmd.Args(cmd, []string{"example.com"}) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestRunA(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args []string | ||
flags map[string]string | ||
}{ | ||
{ | ||
name: "basic check", | ||
args: []string{"example.com"}, | ||
}, | ||
{ | ||
name: "with expected IP", | ||
args: []string{"example.com"}, | ||
flags: map[string]string{ | ||
"expect-ip": "93.184.216.34", | ||
}, | ||
}, | ||
{ | ||
name: "with nameserver", | ||
args: []string{"example.com"}, | ||
flags: map[string]string{ | ||
"nameserver": "8.8.8.8", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cmd := NewACommand() | ||
|
||
for flag, value := range tt.flags { | ||
err := cmd.Flags().Set(flag, value) | ||
assert.NoError(t, err) | ||
} | ||
|
||
err := cmd.Args(cmd, tt.args) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |