awl/main_test.go
Sam Therapy 7edd983175
All checks were successful
continuous-integration/drone/push Build is passing
feat: add preliminary message tinkering (#79)
Reviewed-on: #79
Reviewed-by: grumbulon <grumbulon@grumbulon.xyz>
2022-09-05 00:05:06 +00:00

47 lines
847 B
Go

// SPDX-License-Identifier: BSD-3-Clause
package main
import (
"os"
"testing"
"github.com/stefansundin/go-zflag"
"gotest.tools/v3/assert"
)
func TestMain(t *testing.T) { //nolint: paralleltest // Race conditions
os.Stdout = os.NewFile(0, os.DevNull)
os.Stderr = os.NewFile(0, os.DevNull)
old := os.Args
os.Args = []string{"awl", "+yaml", "@1.1.1.1"}
_, code, err := run()
assert.NilError(t, err)
assert.Equal(t, code, 0)
os.Args = []string{"awl", "+short", "@1.1.1.1"}
_, code, err = run()
assert.NilError(t, err)
assert.Equal(t, code, 0)
os.Args = old
}
func TestHelp(t *testing.T) {
old := os.Args
os.Stdout = os.NewFile(0, os.DevNull)
os.Stderr = os.NewFile(0, os.DevNull)
os.Args = []string{"awl", "-h"}
_, code, err := run()
assert.ErrorIs(t, err, zflag.ErrHelp)
assert.Equal(t, code, 1)
os.Args = old
}