Exemple #1
0
func Execute(config Config) error {
	var err error

	from, err := local.NewLocalFS(config.SourceRepoId)

	if err != nil {
		return err
	}

	to, err := local.NewLocalFS(config.TargetRepoId)

	if err != nil {
		return err
	}

	syncInstance := sync.NewUnidirectionalSync(sync.Config{
		From: from,
		To:   to,
	})

	events, err := syncInstance.Start()

	if err != nil {
		return err
	}

EventLoop:
	for event := range events {
		switch event := event.(type) {

		case *sync.EventStartSyncing:
			switch entry := event.Entry().(type) {

			case storage.DirectoryEntry:
				fmt.Printf("creating %s\n", entry.Path())

			case storage.FileEntry:
				fmt.Printf("syncing %s\n", entry.Path())

			}

		case *sync.EventError:
			fmt.Printf("\nSYNC FAILED: %v\n", event.Error())
			break EventLoop

		case *sync.EventSyncFinished:
			fmt.Printf("\nSYNC SUCCESSFUL\n")
			break EventLoop
		}
	}

	return nil
}
Exemple #2
0
func TestMarshalWithLocalFS(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	cwd, err := os.Getwd()
	w.BailIfError(err)

	referenceJson := []byte(fmt.Sprintf(`{
	    "foo": {
            "plain": true,
            "storage": {
                "type": "local",
                "path": "%s"
            }
        },
        "bar": {
            "plain": true,
            "storage": {
                "type": "local",
                "path": "%s"
            }
        }
	}`, cwd, cwd))

	registry := NewRegistry()

	storage1, err := local.NewLocalFS(".")
	w.BailIfErrorf(err, "unable to init storage: %v", err)

	storage2, err := local.NewLocalFS(".")
	w.BailIfErrorf(err, "unable to init storage: %v", err)

	repo1 := repository.NewRepository(true, storage1)
	repo2 := repository.NewRepository(true, storage2)

	registry.Set("foo", repo1)
	registry.Set("bar", repo2)

	cfg := registry.Marshal()
	jsonData, err := json.Marshal(cfg)
	w.BailIfErrorf(err, "serialization failed: %v", err)

	match, err := testutils.JsonEqual(jsonData, referenceJson)
	w.BailIfErrorf(err, "error parsing JSON: %v", err)

	if !match {
		t.Fatalf("JSON did not match:\n%s\nvs.\n%s", string(jsonData), string(referenceJson))
	}
}
Exemple #3
0
func TestMarshalUnmarshal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error
	version := semver.MustParse("0.0.1")

	provider, err := local.NewLocalFS("./test_artifacts")

	w.BailIfError(err)

	cfg := provider.Marshal()
	jsonData, err := json.Marshal(cfg)

	w.BailIfErrorf(err, "serialization failed: %v", err)

	if !strings.Contains(string(jsonData), "test_artifacts") {
		t.Fatalf("JSON does not contain the proper path: %s", string(jsonData))
	}

	unmarshalledConfig := config.NewConfig(version)
	err = json.Unmarshal(jsonData, &unmarshalledConfig)

	w.BailIfErrorf(err, "deserialization failed: %v", err)

	_, err = FromConfig(unmarshalledConfig)

	w.BailIfErrorf(err, "reinstation of fs provider failed: %v", err)
}
Exemple #4
0
func newLocalFSRepository(path string) (repo repository.Repository, err error) {
	storage, err := local.NewLocalFS(path)

	if err != nil {
		return
	}

	repo = repository.NewRepository(true, storage)

	return
}