Example #1
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)
}
Example #2
0
func TestUnmarshalLocalWithInvalidJSON(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")
	jsonData := `{
	           "type": "local",
	           "path": "."
	       `

	cfg := config.NewConfig(version)
	err = json.Unmarshal([]byte(jsonData), &cfg)

	w.ShouldFailf(err, "unmarshalling should fail due to invalid JSON")
}
Example #3
0
func TestUnmarshalLocalWithInvalidPath(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")
	jsonData := `{
	           "type": "local",
	           "path": "./INVALID_PATH"
	       }`

	cfg := config.NewConfig(version)
	err = json.Unmarshal([]byte(jsonData), &cfg)

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

	_, err = FromConfig(cfg)

	w.ShouldFailf(err, "unmarshalling should fail due to the invalid path")
}
Example #4
0
func TestUnmarshalLocal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")
	jsonData := `{
	           "type": "local",
	           "path": "."
	       }`

	cfg := config.NewConfig(version)
	err = json.Unmarshal([]byte(jsonData), &cfg)

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

	_, err = FromConfig(cfg)

	w.BailIfErrorf(err, "creating the provider failed: %v", err)
}
Example #5
0
func NewConfig(csyncVersion semver.Version) Config {
	return &config_v1{
		StorageConfig_: storage_config.NewConfig(csyncVersion),
	}
}