本文整理汇总了Golang中github.com/spf13/afero.NewMemMapFs函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMemMapFs函数的具体用法?Golang NewMemMapFs怎么用?Golang NewMemMapFs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMemMapFs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestErrorMetadata
func TestErrorMetadata(t *testing.T) {
var checkParseErr = func(path string, expErr string) {
sc := scanner.Scanner{
Position: scanner.Position{
Filename: path,
},
}
f, err := util.Open(path)
if err != nil {
t.Errorf("Couldn't open %s", path)
}
_, err = parse(*sc.Init(f))
if err.Error() != expErr {
t.Errorf("Expected \"%s\"\ngot \"%s\"", expErr, err)
return
}
}
var checkEvalErr = func(path string, expErr string) {
sc := scanner.Scanner{
Position: scanner.Position{
Filename: path,
},
}
f, err := util.Open(path)
if err != nil {
t.Errorf("Couldn't open %s", path)
}
parsed, err := parse(*sc.Init(f))
if err != nil {
t.Errorf("Unexpected parse error: %s", parsed)
}
_, _, err = eval(astRoot(parsed))
if err.Error() != expErr {
t.Errorf("Expected \"%s\"\ngot \"%s\"", expErr, err)
return
}
}
util.AppFs = afero.NewMemMapFs()
util.WriteFile("paren.spec", []byte(`
// This is a comment.
(define Test "abc"`), 0644)
checkParseErr("paren.spec", "paren.spec:3: unbalanced Parenthesis")
util.WriteFile("undefined.spec", []byte(`
(+ 1 b)`), 0644)
checkEvalErr("undefined.spec", "undefined.spec:2: unassigned variable: b")
util.WriteFile("bad_type.spec", []byte(`
(define a "1")
(+ 1 a)`), 0644)
checkEvalErr("bad_type.spec", `bad_type.spec:3: bad arithmetic argument: "1"`)
// Test that functions which evaluate generated S-expressions still have proper
// error messages.
util.WriteFile("generated_sexp.spec", []byte(`(apply + (list 1 "1"))`), 0644)
checkEvalErr("generated_sexp.spec",
`generated_sexp.spec:1: bad arithmetic argument: "1"`)
}
示例2: TestPromptsUser
func TestPromptsUser(t *testing.T) {
oldConfirm := confirm
defer func() {
confirm = oldConfirm
}()
util.AppFs = afero.NewMemMapFs()
for _, confirmResp := range []bool{true, false} {
confirm = func(in io.Reader, prompt string) (bool, error) {
return confirmResp, nil
}
mockGetter := new(testutils.Getter)
c := &clientMock.Client{
ClusterReturn: []db.Cluster{
{
Spec: `{"old":"spec"}`,
},
},
}
mockGetter.On("Client", mock.Anything).Return(c, nil)
util.WriteFile("test.js", []byte(""), 0644)
runCmd := NewRunCommand()
runCmd.clientGetter = mockGetter
runCmd.stitch = "test.js"
runCmd.Run()
assert.Equal(t, confirmResp, c.DeployArg != "")
}
}
示例3: testCheckSpec
func testCheckSpec(t *testing.T) {
initVCSFunc()
os.Setenv("QUILT_PATH", ".")
util.AppFs = afero.NewMemMapFs()
util.AppFs.Mkdir("test", 777)
util.WriteFile("test/noDownload.spec",
[]byte(`(import "nextimport/nextimport")`), 0644)
util.AppFs.Mkdir("nextimport", 777)
util.WriteFile("nextimport/nextimport.spec", []byte("(define dummy 1)"), 0644)
if err := checkSpec("test/noDownload.spec", nil, nil); err != nil {
t.Error(err)
}
if len(created) != 0 {
t.Errorf("should not have downloaded, but downloaded %s", created)
}
// Verify that call is made to GetSpec
util.WriteFile("test/toDownload.spec",
[]byte(`(import "github.com/NetSys/quilt/specs/example")`), 0644)
expected := "unable to open import github.com/NetSys/quilt/specs/example"
if err := checkSpec("test/toDownload.spec", nil, nil); err.Error() != expected {
t.Errorf("expected %s \n but got %s", expected, err.Error())
}
if len(created) == 0 {
t.Error("did not download dependency!")
}
expected = "github.com/NetSys/quilt"
if created[0] != expected {
t.Errorf("expected to download %s \n but got %s", expected, created[0])
}
}
示例4: TestAutoDownload
func TestAutoDownload(t *testing.T) {
util.AppFs = afero.NewMemMapFs()
repoName := "autodownload"
importPath := filepath.Join(repoName, "foo")
util.WriteFile("test.js", []byte(fmt.Sprintf("require(%q);", importPath)), 0644)
logger := newRepoLogger()
getter := ImportGetter{
Path: ".",
repoFactory: logger.newRepoFactory(nil),
}
expErr := "StitchError: unable to open import autodownload/foo: no loadable file"
err := getter.checkSpec("test.js", nil, nil)
if err == nil || err.Error() != expErr {
t.Errorf("Wrong error, expected %q, got %v", expErr, err)
return
}
assert.Equal(t, map[string][]string{
importPath: {repoName},
}, logger.created, "Should autodownload the repo")
assert.Empty(t, logger.updated, "Shouldn't update any repos")
}
示例5: Test_filesystemCredentialStore_GetCredentials_SavedCredentialsAreValid_CredentialsAreReturned
func Test_filesystemCredentialStore_GetCredentials_SavedCredentialsAreValid_CredentialsAreReturned(t *testing.T) {
// arrange
fs := afero.NewMemMapFs()
credentialFilePath := "/home/user/.dee/credentials.json"
// create the initial file
f1, _ := fs.Create(credentialFilePath)
f1.WriteString(`{"Email":"[email protected]","Token":"123456"}`)
f1.Close()
credentialStore := filesystemCredentialStore{fs, credentialFilePath}
// act
credentials, err := credentialStore.GetCredentials()
// assert
if err != nil {
t.Fail()
t.Logf("GetCredentials returned an error: %s", err.Error())
}
if credentials.Email != "[email protected]" || credentials.Token != "123456" {
t.Fail()
t.Logf("GetCredentials did not return the correct credentials. Email: %q, Token: %q", credentials.Email, credentials.Token)
}
}
示例6: TestCmdExec
func TestCmdExec(t *testing.T) {
appFs = afero.NewMemMapFs()
outputPath := "output.log"
log = logger{
cmdLogger: fileLogger(outputPath),
}
expStdout := "standard out"
expStderr := "standard error"
cmd := exec.Command("sh", "-c",
fmt.Sprintf("echo %s ; echo %s 1>&2", expStdout, expStderr))
stdout, stderr, err := execCmd(cmd, "PREFIX")
if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
return
}
if stdout != expStdout {
t.Errorf("Stdout didn't match: expected %s, got %s", expStdout, stdout)
}
if stderr != expStderr {
t.Errorf("Stderr didn't match: expected %s, got %s", expStderr, stderr)
}
}
示例7: TestUpdateNamespace
func TestUpdateNamespace(t *testing.T) {
appFs = afero.NewMemMapFs()
specPath := "/test.spec"
err := overwrite(specPath, `require("spark");
var deployment = createDeployment({namespace: "replace"});
deployment.deploy(new Machine({}));`)
if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
}
updateNamespace(specPath, "test-namespace")
res, err := fileContents(specPath)
exp := `require("spark");
var deployment = createDeployment({namespace: "replace"});
deployment.deploy(new Machine({}));; deployment.namespace = "test-namespace";`
if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
return
}
if res != exp {
t.Errorf("Namespace didn't properly update, expected %s, got %s",
exp, res)
}
}
示例8: TestDefaultKeys
func TestDefaultKeys(t *testing.T) {
util.AppFs = afero.NewMemMapFs()
// Don't pull in keys from the host OS. Setting this environment variable
// is safe because it won't affect the parent shell.
os.Setenv("SSH_AUTH_SOCK", "")
dir, err := homedir.Dir()
if err != nil {
t.Errorf("Failed to get homedir: %q", err.Error())
return
}
sshDir := filepath.Join(dir, ".ssh")
if err := util.AppFs.MkdirAll(sshDir, 0600); err != nil {
t.Errorf("Failed to create SSH directory: %q", err.Error())
return
}
for _, key := range []string{"id_rsa", "id_dsa", "ignored"} {
if err := writeRandomKey(filepath.Join(sshDir, key)); err != nil {
t.Errorf("Failed to write key: %q", err.Error())
return
}
}
signers := defaultSigners()
if len(signers) != 2 {
t.Errorf("Expected two default signers, but got %v", signers)
}
}
示例9: TestCompileAndRun
func TestCompileAndRun(t *testing.T) {
var testProgram = "/$/ {}\n"
store := metrics.NewStore()
lines := make(chan string)
w := watcher.NewFakeWatcher()
fs := afero.NewMemMapFs()
o := LoaderOptions{store, lines, w, fs, false, false, true}
l, err := NewLoader(o)
if err != nil {
t.Fatalf("couldn't create loader: %s", err)
}
if err := l.CompileAndRun("Test", strings.NewReader(testProgram)); err != nil {
t.Errorf("CompileAndRun returned error: %s", err)
}
l.handleMu.Lock()
if len(l.handles) < 1 {
t.Errorf("no vm handles: %v", l.handles)
}
l.handleMu.Unlock()
l.handleMu.Lock()
c := l.handles["Test"].done
if c == nil {
t.Errorf("No done channel in handles: %v", l.handles)
}
l.handleMu.Unlock()
close(lines)
<-c
{
l.handleMu.Lock()
defer l.handleMu.Unlock()
if len(l.handles) != 0 {
t.Errorf("some vm handles: %v", l.handles)
}
}
}
示例10: TestMain
func TestMain(t *testing.T) {
util.AppFs = afero.NewMemMapFs()
util.WriteFile("test.js", []byte(testStitch), 0644)
exitCode := Main([]string{"test.js", "graphviz"})
assert.Zero(t, exitCode)
res, err := util.ReadFile("test.dot")
assert.Nil(t, err)
assert.True(t, isGraphEqual(expGraph, res))
}
示例11: makeTestTail
func makeTestTail(t *testing.T) (*Tailer, chan string, *watcher.FakeWatcher, afero.Fs) {
fs := afero.NewMemMapFs()
w := watcher.NewFakeWatcher()
lines := make(chan string, 1)
o := Options{lines, w, fs}
ta, err := New(o)
if err != nil {
t.Fatal(err)
}
return ta, lines, w, fs
}
示例12: TestSyncKeysError
func TestSyncKeysError(t *testing.T) {
util.AppFs = afero.NewMemMapFs()
conn := db.New()
err := runOnce(conn)
assert.EqualError(t, err, "no self minion")
fs := afero.NewMemMapFs()
util.AppFs = afero.NewReadOnlyFs(fs)
conn.Transact(func(view db.Database) error {
m := view.InsertMinion()
m.Self = true
m.AuthorizedKeys = "keys"
view.Commit(m)
return nil
})
err = runOnce(conn)
assert.EqualError(t, err, "open /home/quilt/.ssh/authorized_keys: "+
"file does not exist")
fs.Create(authorizedKeysFile)
err = runOnce(conn)
assert.EqualError(t, err, "operation not permitted")
}
示例13: Test_filesystemCredentialStore_SaveCredentials_CredentialsAreValid_NoErrorIsReturned
func Test_filesystemCredentialStore_SaveCredentials_CredentialsAreValid_NoErrorIsReturned(t *testing.T) {
// arrange
fs := afero.NewMemMapFs()
credentialFilePath := "/home/user/.dee/credentials.json"
credentialStore := filesystemCredentialStore{fs, credentialFilePath}
// act
err := credentialStore.SaveCredentials(deens.APICredentials{"[email protected]", "123456"})
// assert
if err != nil {
t.Fail()
t.Logf("SaveCredentials should not return an error (%q)", err.Error())
}
}
示例14: Test_filesystemCredentialStore_WithoutSourceFile_DeleteCredentials_credentialsNotFoundErrorIsReturned
func Test_filesystemCredentialStore_WithoutSourceFile_DeleteCredentials_credentialsNotFoundErrorIsReturned(t *testing.T) {
// arrange
fs := afero.NewMemMapFs()
credentialFilePath := "/home/user/.dee/credentials.json"
credentialStore := filesystemCredentialStore{fs, credentialFilePath}
// act
err := credentialStore.DeleteCredentials()
// assert
if !isNoCredentialsError(err) {
t.Fail()
t.Logf("DeleteCredentials should return a noCredentials-error if the credential store has no source file.")
}
}
示例15: TestSyncKeys
func TestSyncKeys(t *testing.T) {
tests := []keyTest{
{
dbKeys: "key1\nkey2",
expKeyFile: "key1\nkey2",
},
{
dbKeys: "key1\nkey2",
keyFile: "key1",
expKeyFile: "key1\nkey2",
},
{
dbKeys: "key1\nkey2",
keyFile: "key1\nkey2",
expKeyFile: "key1\nkey2",
},
{
keyFile: "key1\nkey2",
expKeyFile: "",
},
}
for _, test := range tests {
util.AppFs = afero.NewMemMapFs()
if test.keyFile != "" {
err := util.WriteFile(
authorizedKeysFile, []byte(test.keyFile), 0644)
assert.NoError(t, err)
}
conn := db.New()
conn.Transact(func(view db.Database) error {
m := view.InsertMinion()
m.Self = true
m.AuthorizedKeys = test.dbKeys
view.Commit(m)
return nil
})
err := runOnce(conn)
assert.NoError(t, err)
actual, err := util.ReadFile(authorizedKeysFile)
assert.NoError(t, err)
assert.Equal(t, test.expKeyFile, actual)
}
}