-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/relui: add persistence to development database
This change renames memoryStore to fileStore, and persists data created in the UI. This will help make local development less painful when testing changes. Data stored is intended to be loaded at start-up, which will be implemented in a future change. For golang/go#40279 Co-authored-by: Carlos Amedee <[email protected]> Change-Id: Id2390c35b8e1d1d368fbf7ac13b3cdef0776ad87 Reviewed-on: https://go-review.googlesource.com/c/build/+/246298 Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Andrew Bonventre <[email protected]>
- Loading branch information
1 parent
0768812
commit 1c75e20
Showing
7 changed files
with
216 additions
and
55 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/golang/protobuf/proto" | ||
"github.com/google/go-cmp/cmp" | ||
reluipb "golang.org/x/build/cmd/relui/protos" | ||
) | ||
|
||
func TestFileStorePersist(t *testing.T) { | ||
dir, err := ioutil.TempDir("", "memory-store-test") | ||
if err != nil { | ||
t.Fatalf("ioutil.TempDir(%q, %q) = _, %v", "", "memory-store-test", err) | ||
} | ||
defer os.RemoveAll(dir) | ||
want := &reluipb.LocalStorage{ | ||
Workflows: []*reluipb.Workflow{ | ||
{ | ||
Name: "Persist Test", | ||
BuildableTasks: []*reluipb.BuildableTask{{Name: "Persist Test Task"}}, | ||
}, | ||
}, | ||
} | ||
fs := newFileStore(filepath.Join(dir, "relui")) | ||
fs.ls = want | ||
|
||
err = fs.persist() | ||
if err != nil { | ||
t.Fatalf("fs.Persist() = %v, wanted no error", err) | ||
} | ||
|
||
b, err := ioutil.ReadFile(filepath.Join(dir, "relui", fileStoreName)) | ||
if err != nil { | ||
t.Fatalf("ioutil.ReadFile(%q) = _, %v, wanted no error", filepath.Join(dir, "relui", fileStoreName), err) | ||
} | ||
got := new(reluipb.LocalStorage) | ||
err = proto.UnmarshalText(string(b), got) | ||
if err != nil { | ||
t.Fatalf("proto.UnmarshalText(_) = %v, wanted no error", err) | ||
} | ||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("reluipb.LocalStorage mismatch (-want, +got):\n%s", diff) | ||
} | ||
} |
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