Example #1
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))
	}
}
Example #2
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
}