Пример #1
0
func TestPrintVersion(t *testing.T) {
	version.Arch = "Linux-x86_64"
	version.Branch = "master"
	version.ShaLong = gotil.RandomString(32)
	version.Epoch = fmt.Sprintf("%d", time.Now().Unix())
	version.SemVer = "1.0.0"
	_, _, thisAbsPath := gotil.GetThisPathParts()
	epochStr := version.EpochToRfc1123()

	t.Logf("thisAbsPath=%s", thisAbsPath)
	t.Logf("epochStr=%s", epochStr)

	var buff []byte
	b := bytes.NewBuffer(buff)

	PrintVersion(b)

	vs := b.String()

	evs := `Binary: ` + thisAbsPath + `
SemVer: ` + version.SemVer + `
OsArch: ` + version.Arch + `
Branch: ` + version.Branch + `
Commit: ` + version.ShaLong + `
Formed: ` + epochStr + `
`

	if vs != evs {
		t.Fatalf("nexpectedVersionString=%s\n\nversionString=%s\n", evs, vs)
	}
}
Пример #2
0
func (c *CLI) tryToStartDaemon() {
	_, _, thisAbsPath := gotil.GetThisPathParts()

	fmt.Print("Starting REX-Ray...")

	signal := make(chan byte)
	client := fmt.Sprintf("%s/%s.sock", os.TempDir(), gotil.RandomString(32))
	log.WithField("client", client).Debug("trying to start service")

	l, lErr := net.Listen("unix", client)
	failOnError(lErr)

	go func() {
		conn, acceptErr := l.Accept()
		if acceptErr != nil {
			fmt.Printf("FAILED!\n  %v\n", acceptErr)
			panic(acceptErr)
		}
		defer conn.Close()
		defer os.Remove(client)

		log.Debug("accepted connection")

		buff := make([]byte, 1)
		conn.Read(buff)

		log.Debug("received data")

		signal <- buff[0]
	}()

	cmdArgs := []string{
		"start",
		fmt.Sprintf("--client=%s", client),
		fmt.Sprintf("--logLevel=%v", c.logLevel())}

	if c.host() != "" {
		cmdArgs = append(cmdArgs, fmt.Sprintf("--host=%s", c.host()))
	}

	cmd := exec.Command(thisAbsPath, cmdArgs...)
	cmd.Stderr = os.Stderr

	cmdErr := cmd.Start()
	failOnError(cmdErr)

	sigVal := <-signal
	if sigVal != 0 {
		fmt.Println("FAILED!")
		panic(1)
	}

	pid, _ := util.ReadPidFile()
	fmt.Printf("SUCCESS!\n\n")
	fmt.Printf("  The REX-Ray daemon is now running at PID %d. To\n", pid)
	fmt.Printf("  shutdown the daemon execute the following command:\n\n")
	fmt.Printf("    sudo %s stop\n\n", thisAbsPath)
}
Пример #3
0
func TestMain(m *testing.M) {
	r10 = gotil.RandomString(10)

	exitCode := m.Run()
	for _, d := range tmpPrefixDirs {
		os.RemoveAll(d)
	}
	os.Exit(exitCode)
}
Пример #4
0
func TestPrintVersion(t *testing.T) {
	// this test works, and adding the libStorage info in just makes it more
	// trouble than it's worth right now to fix
	t.SkipNow()

	core.Version = &apitypes.VersionInfo{}
	core.Version.Arch = "Linux-x86_64"
	core.Version.Branch = "master"
	core.Version.ShaLong = gotil.RandomString(32)
	core.Version.BuildTimestamp = time.Now()
	core.Version.SemVer = "1.0.0"
	_, _, thisAbsPath := gotil.GetThisPathParts()
	epochStr := core.Version.BuildTimestamp.Format(time.RFC1123)

	t.Logf("thisAbsPath=%s", thisAbsPath)
	t.Logf("epochStr=%s", epochStr)

	var buff []byte
	b := bytes.NewBuffer(buff)

	PrintVersion(b)

	vs := b.String()

	evs := `Binary: ` + thisAbsPath + `
SemVer: ` + core.Version.SemVer + `
OsArch: ` + core.Version.Arch + `
Branch: ` + core.Version.Branch + `
Commit: ` + core.Version.ShaLong + `
Formed: ` + epochStr + `
`

	if vs != evs {
		t.Fatalf("nexpectedVersionString=%s\n\nversionString=%s\n", evs, vs)
	}
}
Пример #5
0
func TestNewWithBadConfigFilePath(t *testing.T) {
	if _, err := rexray.NewWithConfigFile(gotil.RandomString(10)); err == nil {
		t.Fatal("expected error from bad config file path")
	}
}