func TestAddCommandNoForceNoOverwrite(t *testing.T) {
	cmd, err := commands.ParseAddCommand(completeAddExample[2:])

	if err != nil {
		t.Error("Error parsing command")
	}

	addCommand, ok := cmd.(*commands.AddCommand)

	if !ok {
		t.Fatal("Parsed command is not an AddCommand")
	}

	addCommand.IsForce = false

	config := proxyconfig.NewConfig()
	config.Rewrites[source] = firstDestination

	err = addCommand.Execute(func() (*proxyconfig.Config, error) {
		return config, nil
	})

	put, ok := config.Rewrites[source]

	if err == nil {
		t.Errorf("No error thrown on existing key")
	}

	if !ok || put == destination {
		t.Errorf("Source-dest mapping made, force not defined")
	}
}
func TestAddCommandForceOverwrite(t *testing.T) {
	cmd, err := commands.ParseAddCommand(completeAddExample[2:])

	if err != nil {
		t.Error("Error parsing command")
	}

	addCommand, ok := cmd.(*commands.AddCommand)

	if !ok {
		t.Fatal("Parsed command is not an AddCommand")
	}

	config := proxyconfig.NewConfig()
	config.Rewrites[source] = firstDestination

	addCommand.Execute(func() (*proxyconfig.Config, error) {
		return config, nil
	})

	put, ok := config.Rewrites[source]

	if !ok || put != destination {
		t.Errorf("Source-dest mapping not made")
	}
}
Beispiel #3
0
//Config should alwyas be nil
func (initCmd *InitCommand) Execute(configLoader ConfigLoader) error {
	config := proxyconfig.NewConfig()
	config.Verbose = initCmd.IsVerbose
	config.SaveToFile(proxyconfig.DefaultConfigFile)

	configLoader()

	return nil
}