func TestAcceptance(t *testing.T) {
	var err error
	conf := config.ParseConfig(true)
	if conf.Acceptance == false {
		t.Skip("Skipping acceptance test, Set ACCEPTANCE_TEST=1 to run")
	}
	command := "consul"
	commandargs := []string{"agent", "-dev", "-bind=127.0.0.1"}
	cmd := &LocalDevConsul{Command: command, CommandArgs: commandargs}
	go cmd.Run()

	// 5-10 seconds is about the time it takes for consul to wake up
	time.Sleep(5 * time.Second)

	c := consul.Client()

	seedData := &Seeder{}

	t.Log("Adding random seed data to consul kv")
	for i := 1; i < 500; i++ {
		// more entropy is needed here.
		randname := fmt.Sprintf("%s.%s", randomdata.SillyName(), randomdata.SillyName())
		err = putKey(c, randname, randomdata.Address(), seedData)
		if err != nil {
			t.Errorf("Failed putting test data to kv: %v", err)
		}
		err = putKey(c, randomdata.IpV4Address(), randomdata.Paragraph(), seedData)
		if err != nil {
			t.Errorf("Failed putting test data to kv: %v", err)
		}
	}

	t.Log("Starting Backup")

	backup.Runner("test")

	_, err = c.KV().DeleteTree("", nil)
	if err != nil {
		for _, i := range cmd.CommandOut {
			log.Printf("CONSUL: %v", i)
		}
		t.Errorf("Unable to clear consul kv store after backup; %v", err)
	}

	restore.Runner("/tmp/acceptancetest.tar.gz")

	for _, kv := range seedData.Data {
		//log.Printf("SEED: %v | %v", kv.Key, string(kv.Value))
		err := checkKey(c, kv)
		if err != nil {
			for _, i := range cmd.CommandOut {
				log.Printf("CONSUL: %v", i)
			}
			t.Errorf("Key Failure: %v", err)
		}
	}

	// Remove the staging path
	err = os.RemoveAll("/tmp/acceptancetest")
	if err != nil {
		log.Printf("Unable to remove temporary backup file: %v", err)
	}

	err = os.RemoveAll("/tmp/acceptancetest.tar.gz")
	if err != nil {
		log.Printf("Unable to remove temporary backup file: %v", err)
	}

}
Beispiel #2
0
// Run the backup via backup.Runner
func (c *BackupCommand) Run(args []string) int {
	c.UI.Info(fmt.Sprintf("v%v: Starting Consul Snapshot", c.Version))
	response := backup.Runner(c.Version)
	// Actually need to return the proper response here.
	return response
}