-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3102 from flipt-io/gm/git-filesystem-storage
feat(fs/git): add support for cloning target repository to the local filesystem
- Loading branch information
Showing
6 changed files
with
181 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -675,6 +675,9 @@ func TestLoad(t *testing.T) { | |
cfg.Storage = StorageConfig{ | ||
Type: GitStorageType, | ||
Git: &Git{ | ||
Backend: GitBackend{ | ||
Type: GitBackendMemory, | ||
}, | ||
Repository: "https://github.com/flipt-io/flipt.git", | ||
Ref: "production", | ||
RefType: GitRefTypeStatic, | ||
|
@@ -817,6 +820,9 @@ func TestLoad(t *testing.T) { | |
cfg.Storage = StorageConfig{ | ||
Type: GitStorageType, | ||
Git: &Git{ | ||
Backend: GitBackend{ | ||
Type: GitBackendMemory, | ||
}, | ||
Ref: "main", | ||
RefType: GitRefTypeStatic, | ||
Repository: "[email protected]:foo/bar.git", | ||
|
@@ -834,6 +840,9 @@ func TestLoad(t *testing.T) { | |
cfg.Storage = StorageConfig{ | ||
Type: GitStorageType, | ||
Git: &Git{ | ||
Backend: GitBackend{ | ||
Type: GitBackendMemory, | ||
}, | ||
Ref: "main", | ||
RefType: GitRefTypeStatic, | ||
Repository: "[email protected]:foo/bar.git", | ||
|
@@ -852,6 +861,9 @@ func TestLoad(t *testing.T) { | |
cfg.Storage = StorageConfig{ | ||
Type: GitStorageType, | ||
Git: &Git{ | ||
Backend: GitBackend{ | ||
Type: GitBackendMemory, | ||
}, | ||
Ref: "main", | ||
RefType: GitRefTypeSemver, | ||
Repository: "[email protected]:foo/bar.git", | ||
|
@@ -862,6 +874,27 @@ func TestLoad(t *testing.T) { | |
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "git config provided with ref_type", | ||
path: "./testdata/storage/git_provided_with_backend_type.yml", | ||
expected: func() *Config { | ||
cfg := Default() | ||
cfg.Storage = StorageConfig{ | ||
Type: GitStorageType, | ||
Git: &Git{ | ||
Backend: GitBackend{ | ||
Type: GitBackendFilesystem, | ||
Path: "/path/to/gitdir", | ||
}, | ||
Ref: "main", | ||
RefType: GitRefTypeStatic, | ||
Repository: "[email protected]:foo/bar.git", | ||
PollInterval: 30 * time.Second, | ||
}, | ||
} | ||
return cfg | ||
}, | ||
}, | ||
{ | ||
name: "git repository not provided", | ||
path: "./testdata/storage/invalid_git_repo_not_specified.yml", | ||
|
@@ -900,6 +933,9 @@ func TestLoad(t *testing.T) { | |
cfg.Storage = StorageConfig{ | ||
Type: GitStorageType, | ||
Git: &Git{ | ||
Backend: GitBackend{ | ||
Type: GitBackendMemory, | ||
}, | ||
Ref: "main", | ||
RefType: GitRefTypeStatic, | ||
Repository: "[email protected]:foo/bar.git", | ||
|
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
7 changes: 7 additions & 0 deletions
7
internal/config/testdata/storage/git_provided_with_backend_type.yml
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,7 @@ | ||
storage: | ||
type: git | ||
git: | ||
repository: "[email protected]:foo/bar.git" | ||
backend: | ||
type: "filesystem" | ||
path: "/path/to/gitdir" |
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 |
---|---|---|
|
@@ -121,6 +121,86 @@ flags: | |
})) | ||
} | ||
|
||
func Test_Store_View_WithFilesystemStorage(t *testing.T) { | ||
ch := make(chan struct{}) | ||
store, skip := testStore(t, gitRepoURL, | ||
WithFilesystemStorage(t.TempDir()), | ||
WithPollOptions( | ||
fs.WithInterval(time.Second), | ||
fs.WithNotify(t, func(modified bool) { | ||
if modified { | ||
close(ch) | ||
} | ||
}), | ||
)) | ||
if skip { | ||
return | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
// pull repo | ||
workdir := memfs.New() | ||
repo, err := git.Clone(memory.NewStorage(), workdir, &git.CloneOptions{ | ||
Auth: &http.BasicAuth{Username: "root", Password: "password"}, | ||
URL: gitRepoURL, | ||
RemoteName: "origin", | ||
ReferenceName: plumbing.NewBranchReferenceName("main"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
tree, err := repo.Worktree() | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, tree.Checkout(&git.CheckoutOptions{ | ||
Branch: "refs/heads/main", | ||
})) | ||
|
||
// update features.yml | ||
fi, err := workdir.OpenFile("features.yml", os.O_TRUNC|os.O_RDWR, os.ModePerm) | ||
require.NoError(t, err) | ||
|
||
updated := []byte(`namespace: production | ||
flags: | ||
- key: foo | ||
name: Foo`) | ||
|
||
_, err = fi.Write(updated) | ||
require.NoError(t, err) | ||
require.NoError(t, fi.Close()) | ||
|
||
// commit changes | ||
_, err = tree.Commit("chore: update features.yml", &git.CommitOptions{ | ||
All: true, | ||
Author: &object.Signature{Email: "[email protected]", Name: "dev"}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// push new commit | ||
require.NoError(t, repo.Push(&git.PushOptions{ | ||
Auth: &http.BasicAuth{Username: "root", Password: "password"}, | ||
RemoteName: "origin", | ||
})) | ||
|
||
// wait until the snapshot is updated or | ||
// we timeout | ||
select { | ||
case <-ch: | ||
case <-time.After(time.Minute): | ||
t.Fatal("timed out waiting for snapshot") | ||
} | ||
|
||
require.NoError(t, err) | ||
|
||
t.Log("received new snapshot") | ||
|
||
require.NoError(t, store.View(ctx, "", func(s storage.ReadOnlyStore) error { | ||
_, err = s.GetFlag(ctx, storage.NewResource("production", "foo")) | ||
return err | ||
})) | ||
} | ||
|
||
func Test_Store_View_WithRevision(t *testing.T) { | ||
ch := make(chan struct{}) | ||
store, skip := testStore(t, gitRepoURL, WithPollOptions( | ||
|
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