awl/cli/cli_test.go
Sam Therapy 92812c337f
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Another day's work
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-21 19:06:46 -05:00

211 lines
4.9 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package cli_test
import (
"os"
"testing"
"git.froth.zone/sam/awl/cli"
"gotest.tools/v3/assert"
)
func TestEmpty(t *testing.T) {
old := os.Args
os.Args = []string{""}
opts, err := cli.ParseCLI("TEST")
assert.NilError(t, err)
assert.Assert(t, opts != cli.Options{})
os.Args = old
}
func TestInvalidFlag(t *testing.T) {
old := os.Args
os.Args = []string{"awl", "--treebug"}
_, err := cli.ParseCLI("TEST")
assert.ErrorContains(t, err, "unknown flag")
os.Args = old
}
func TestInvalidDig(t *testing.T) {
old := os.Args
os.Args = []string{"awl", "+a"}
_, err := cli.ParseCLI("TEST")
assert.ErrorContains(t, err, "dig: unknown flag given")
os.Args = old
}
// func TestArgParse(t *testing.T) {
// tests := []struct {
// in []string
// want helpers.Request
// }{
// {
// []string{"@::1", "localhost", "AAAA"},
// helpers.Request{Server: "::1", Type: dns.TypeAAAA, Name: "localhost"},
// },
// {
// []string{"@1.0.0.1", "google.com"},
// helpers.Request{Server: "1.0.0.1", Type: dns.TypeA, Name: "google.com"},
// },
// {
// []string{"@8.8.4.4"},
// helpers.Request{Server: "8.8.4.4", Type: dns.TypeNS, Name: "."},
// },
// }
// for _, test := range tests {
// old := os.Args
// act, err := cli.ParseCLI(test.in)
// assert.Nil(t, err)
// assert.Equal(t, test.want, act)
// }
// }
func FuzzFlags(f *testing.F) {
testcases := []string{"git.froth.zone", "", "!12345", "google.com.edu.org.fr"}
for _, tc := range testcases {
f.Add(tc)
}
f.Fuzz(func(t *testing.T, orig string) {
os.Args = []string{orig}
//nolint:errcheck // Only make sure the program does not crash
cli.ParseCLI("TEST")
})
}
// func TestArgParse(t *testing.T) {
// t.Parallel()
// tests := []struct {
// in []string
// want helpers.Request
// }{
// {
// []string{"@::1", "localhost", "AAAA"},
// helpers.Request{Server: "::1", Type: dns.TypeAAAA, Name: "localhost"},
// },
// {
// []string{"@1.0.0.1", "google.com"},
// helpers.Request{Server: "1.0.0.1", Type: dns.TypeA, Name: "google.com"},
// },
// {
// []string{"@8.8.4.4"},
// helpers.Request{Server: "8.8.4.4", Type: dns.TypeNS, Name: "."},
// },
// }
// for _, test := range tests {
// act, err := parseArgs(test.in, &query.Options{})
// assert.Nil(t, err)
// assert.Equal(t, test.want, act)
// }
// }
// func TestQuery(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "--Treebug")
// err := app.Run(args)
// assert.NotNil(t, err)
// }
// func TestNoArgs(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "--no-truncate")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestFlags(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "--debug")
// args = append(args, "--short")
// args = append(args, "-4")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestHTTPS(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-H")
// // args = append(args, "@https://cloudflare-dns.com/dns-query")
// args = append(args, "git.froth.zone")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestJSON(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-j")
// args = append(args, "git.froth.zone")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestTLS(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-T")
// args = append(args, "git.froth.zone")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestXML(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-X")
// args = append(args, "git.froth.zone")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestYAML(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-y")
// args = append(args, "git.froth.zone")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestQUIC(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-Q")
// // args = append(args, "@dns.adguard.com")
// args = append(args, "git.froth.zone")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func TestReverse(t *testing.T) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, "-x")
// args = append(args, "8.8.8.8")
// err := app.Run(args)
// assert.Nil(t, err)
// }
// func FuzzCli(f *testing.F) {
// testcases := []string{"git.froth.zone", "", "!12345", "google.com.edu.org.fr"}
// for _, tc := range testcases {
// f.Add(tc)
// }
// f.Fuzz(func(t *testing.T, orig string) {
// app := prepareCLI()
// args := os.Args[0:1]
// args = append(args, orig)
// err := app.Run(args)
// if err != nil {
// require.ErrorContains(t, err, "domain must be fully qualified")
// }
// require.Nil(t, err)
// })
// }