forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go-ipfs-config: Merge pull request ipfs#128 from ipfs/feat/migration-…
…config Add config for downloading repo migrations
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package config | ||
|
||
const DefaultMigrationKeep = "cache" | ||
|
||
var DefaultMigrationDownloadSources = []string{"HTTPS", "IPFS"} | ||
|
||
// Migration configures how migrations are downloaded and if the downloads are | ||
// added to IPFS locally | ||
type Migration struct { | ||
// Sources in order of preference, where "IPFS" means use IPFS and "HTTPS" | ||
// means use default gateways. Any other values are interpreted as | ||
// hostnames for custom gateways. Empty list means "use default sources". | ||
DownloadSources []string | ||
// Whether or not to keep the migration after downloading it. | ||
// Options are "discard", "cache", "pin". Empty string for default. | ||
Keep string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
func TestMigrationDecode(t *testing.T) { | ||
str := ` | ||
{ | ||
"DownloadSources": ["IPFS", "HTTP", "127.0.0.1"], | ||
"Keep": "cache" | ||
} | ||
` | ||
|
||
var cfg Migration | ||
if err := json.Unmarshal([]byte(str), &cfg); err != nil { | ||
t.Errorf("failed while unmarshalling migration struct: %s", err) | ||
} | ||
|
||
if len(cfg.DownloadSources) != 3 { | ||
t.Fatal("wrong number of DownloadSources") | ||
} | ||
expect := []string{"IPFS", "HTTP", "127.0.0.1"} | ||
for i := range expect { | ||
if cfg.DownloadSources[i] != expect[i] { | ||
t.Errorf("wrong DownloadSource at %d", i) | ||
} | ||
} | ||
|
||
if cfg.Keep != "cache" { | ||
t.Error("wrong value for Keep") | ||
} | ||
} |