示例#1
0
// test exporting auth tokens
func TestExport(t *testing.T) {
	token := &bytes.Buffer{}
	err := authenticator.ExportLogvac(token)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}

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

	var exportWriter io.Writer
	if portFile != "" {
		exportWriter, err = os.Create(portFile)
		if err != nil {
			return fmt.Errorf("Failed to open file - %v", err)
		}
	} else {
		exportWriter = os.NewFile(uintptr(syscall.Stdout), "/dev/stdout") // stdout
	}

	err = authenticator.ExportLogvac(exportWriter)
	if err != nil {
		return fmt.Errorf("Failed to export - %v", err)
	}

	return nil
}