示例#1
0
// test importing auth tokens
func TestImport(t *testing.T) {
	token := &bytes.Buffer{}
	token.Write([]byte("[\"user2\"]"))
	err := authenticator.ImportLogvac(token)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

	if string(token.Bytes()) != "" {
		t.Errorf("%q doesn't match expected out", token)
		t.FailNow()
	}
}
示例#2
0
文件: main.go 项目: nanopack/logvac
func importLogvac(ccmd *cobra.Command, args []string) error {
	err := authenticator.Init()
	if err != nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}

	var importReader io.Reader
	if portFile != "" {
		importReader, err = os.Open(portFile)
		if err != nil {
			return fmt.Errorf("Failed to open file - %v", err)
		}
	} else {
		importReader = os.NewFile(uintptr(syscall.Stdin), "/dev/stdin") // stdin
	}

	err = authenticator.ImportLogvac(importReader)
	if err != nil {
		return fmt.Errorf("Failed to import - %v", err)
	}

	return nil
}