You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/command/configtest_test.go

86 lines
1.7 KiB

package command
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/hashicorp/consul/testutil"
"github.com/mitchellh/cli"
)
func testConfigTestCommand(t *testing.T) (*cli.MockUi, *ConfigTestCommand) {
ui := cli.NewMockUi()
return ui, &ConfigTestCommand{
BaseCommand: BaseCommand{
UI: ui,
Flags: FlagSetNone,
},
}
}
func TestConfigTestCommand_implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &ConfigTestCommand{}
}
func TestConfigTestCommandFailOnEmptyFile(t *testing.T) {
t.Parallel()
tmpFile := testutil.TempFile(t, "consul")
defer os.RemoveAll(tmpFile.Name())
_, cmd := testConfigTestCommand(t)
args := []string{
"-config-file", tmpFile.Name(),
}
if code := cmd.Run(args); code == 0 {
t.Fatalf("bad: %d", code)
}
}
func TestConfigTestCommandSucceedOnMinimalConfigFile(t *testing.T) {
t.Parallel()
td := testutil.TempDir(t, "consul")
defer os.RemoveAll(td)
fp := filepath.Join(td, "config.json")
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir": "`+td+`"}`), 0644)
if err != nil {
t.Fatalf("err: %s", err)
}
_, cmd := testConfigTestCommand(t)
args := []string{
"-config-file", fp,
}
if code := cmd.Run(args); code != 0 {
t.Fatalf("bad: %d", code)
}
}
func TestConfigTestCommandSucceedOnMinimalConfigDir(t *testing.T) {
t.Parallel()
td := testutil.TempDir(t, "consul")
defer os.RemoveAll(td)
err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir": "`+td+`"}`), 0644)
if err != nil {
t.Fatalf("err: %s", err)
}
_, cmd := testConfigTestCommand(t)
args := []string{
"-config-dir", td,
}
if code := cmd.Run(args); code != 0 {
t.Fatalf("bad: %d", code)
}
}