func TestMarshalUnmarshal(t *testing.T) { w := testutils.Wrap(t) var err error version := semver.MustParse("0.0.1") provider := getFSInstace() cfg := provider.Marshal() jsonData, err := json.Marshal(cfg) w.BailIfErrorf(err, "serialization failed: %v", err) unmarshalCfg := config.NewConfig(version) err = json.Unmarshal(jsonData, &unmarshalCfg) w.BailIfErrorf(err, "deserialization failed: %v", err) unmarshalledProvider, err := FromConfig(unmarshalCfg) w.BailIfErrorf(err, "instatiation failed: %v", err) root, err := unmarshalledProvider.Root() w.BailIfError(err) _, err = checkDirectoryContents(root, expectedRootEntries()) w.BailIfErrorf(err, "provider path differs") }
func TestUnmarshal(t *testing.T) { w := testutils.Wrap(t) var err error version := semver.MustParse("0.0.1") jsonData := []byte(`{ "version": "0.0.1", "path": "./test_artifacts" }`) cfg := config.NewConfig(version) err = json.Unmarshal(jsonData, &cfg) w.BailIfErrorf(err, "deserializazion failed: %v", err) provider, err := FromConfig(cfg) w.BailIfErrorf(err, "instantiation failed: %v", err) root, err := provider.Root() w.BailIfError(err) _, err = checkDirectoryContents(root, expectedRootEntries()) w.BailIfErrorf(err, "provider path differs") }
func TestUnmarshalLocalFromSpecificConfig(t *testing.T) { w := testutils.Wrap(t) var err error version := semver.MustParse("0.0.1") jsonData := `{ "type": "local", "path": "." }` cfg := config_local.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) }
// Try to identify the storage provider by type and unmarshal the wrapper // accordingly. The result is suitable for storage/factory . func (m *unspecificConfig) UnmarshalJSON(jsonData []byte) (err error) { var protoConfig struct { Type string `json:"type"` } err = json.Unmarshal(jsonData, &protoConfig) if err != nil { return } switch protoConfig.Type { case types.LOCAL: m.Config = config_local.NewConfig(m.forVersion) default: err = errors.New("invalid type") return } err = json.Unmarshal(jsonData, m.Config) return }