Example #1
0
// testClient returns a *Client connected to a localy running sftp-server
// the *exec.Cmd returned must be defer Wait'd.
func testClient(t testing.TB, readonly bool, delay time.Duration) (*Client, *exec.Cmd) {
	if !*testIntegration {
		t.Skip("skipping intergration test")
	}
	cmd := exec.Command(*testSftp, "-e", "-R", "-l", debuglevel) // log to stderr, read only
	if !readonly {
		cmd = exec.Command(*testSftp, "-e", "-l", debuglevel) // log to stderr
	}
	cmd.Stderr = os.Stdout
	pw, err := cmd.StdinPipe()
	if err != nil {
		t.Fatal(err)
	}
	if delay > NO_DELAY {
		pw = newDelayedWriter(pw, delay)
	}
	pr, err := cmd.StdoutPipe()
	if err != nil {
		t.Fatal(err)
	}
	if err := cmd.Start(); err != nil {
		t.Skipf("could not start sftp-server process: %v", err)
	}

	sftp, err := NewClientPipe(pr, pw)
	if err != nil {
		t.Fatal(err)
	}

	return sftp, cmd
}
Example #2
0
func skipIfNotUnix(tb testing.TB) {
	switch runtime.GOOS {
	case "android", "nacl", "plan9", "windows":
		tb.Skipf("%s does not support unix sockets", runtime.GOOS)
	}
	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
		tb.Skip("iOS does not support unix, unixgram")
	}
}
Example #3
0
func checkKafkaAvailability(t testing.TB) {
	if !kafkaAvailable {
		if kafkaRequired {
			t.Fatalf("Kafka broker is not available on %s. Set KAFKA_PEERS to connect to Kafka on a different location.", kafkaBrokers[0])
		} else {
			t.Skipf("Kafka broker is not available on %s. Set KAFKA_PEERS to connect to Kafka on a different location.", kafkaBrokers[0])
		}
	}
}
Example #4
0
func readFile(b testing.TB, filename string) []byte {
	src, err := ioutil.ReadFile(filename)
	if err != nil {
		b.Skipf("skipping benchmark: %v", err)
	}
	if len(src) == 0 {
		b.Fatalf("%s has zero length", filename)
	}
	return src
}
Example #5
0
func readFile(t testing.TB, filename string) []byte {
	t.Logf("opening file %s", filename)
	p := filepath.Join("testdata", filepath.FromSlash(filename))
	data, err := ioutil.ReadFile(p)
	if err != nil {
		if os.IsNotExist(err) {
			t.Skipf("missing file %s", p)
		}
		t.Fatal(err)
	}
	return data
}
Example #6
0
func checkKafkaVersion(t testing.TB, requiredVersion string) {
	kafkaVersion := os.Getenv("KAFKA_VERSION")
	if kafkaVersion == "" {
		t.Logf("No KAFKA_VERSION set. This test requires Kafka version %s or higher. Continuing...", requiredVersion)
	} else {
		available := parseKafkaVersion(kafkaVersion)
		required := parseKafkaVersion(requiredVersion)
		if !available.satisfies(required) {
			t.Skipf("Kafka version %s is required for this test; you have %s. Skipping...", requiredVersion, kafkaVersion)
		}
	}
}
Example #7
0
func skipNotImplemented(t testing.TB, err error, goos ...string) error {
	for _, os := range goos {
		if runtime.GOOS == os {
			if err == nil {
				t.Fatal("expected ErrNotImplemented")
			} else if IsNotImplemented(err) {
				t.Skipf("Skipping test on %s", runtime.GOOS)
			}

			break
		}
	}

	return err
}
Example #8
0
func requiresImage(t testing.TB, img string) {
	cli, err := docker.NewDefaultClient(time.Second * 3)
	if err != nil {
		t.Fatal(err)
	}
	_, err = cli.InspectImage(img)
	if err == docker.ErrNotFound {
		if strings.HasPrefix(img, "yhat/integration") {
			t.Skipf("Integration tests require you to build image '%s' beforehand. Use integration/build-test-images.sh to generate the images.", img)
		} else {
			t.Skipf("test requires docker image %s, skipping for now", img)
		}
	}
	if err != nil {
		t.Fatal(err)
	}
}
Example #9
0
func newDriver(t testing.TB, name string, options []string) *Driver {
	root, err := ioutil.TempDir("", "docker-graphtest-")
	if err != nil {
		t.Fatal(err)
	}

	if err := os.MkdirAll(root, 0755); err != nil {
		t.Fatal(err)
	}

	d, err := graphdriver.GetDriver(name, root, options, nil, nil)
	if err != nil {
		t.Logf("graphdriver: %v\n", err)
		if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites || err == graphdriver.ErrIncompatibleFS {
			t.Skipf("Driver %s not supported", name)
		}
		t.Fatal(err)
	}
	return &Driver{d, root, 1}
}
Example #10
0
func downloadBenchmarkFiles(b testing.TB, basename string) (errRet error) {
	bDir := filepath.FromSlash(*benchdataDir)
	filename := filepath.Join(bDir, basename)
	if stat, err := os.Stat(filename); err == nil && stat.Size() != 0 {
		return nil
	}

	if !*download {
		b.Skipf("test data not found; skipping %s without the -download flag", testOrBenchmark(b))
	}
	// Download the official snappy C++ implementation reference test data
	// files for benchmarking.
	if err := os.MkdirAll(bDir, 0777); err != nil && !os.IsExist(err) {
		return fmt.Errorf("failed to create %s: %s", bDir, err)
	}

	f, err := os.Create(filename)
	if err != nil {
		return fmt.Errorf("failed to create %s: %s", filename, err)
	}
	defer f.Close()
	defer func() {
		if errRet != nil {
			os.Remove(filename)
		}
	}()
	url := benchURL + basename
	resp, err := http.Get(url)
	if err != nil {
		return fmt.Errorf("failed to download %s: %s", url, err)
	}
	defer resp.Body.Close()
	if s := resp.StatusCode; s != http.StatusOK {
		return fmt.Errorf("downloading %s: HTTP status code %d (%s)", url, s, http.StatusText(s))
	}
	_, err = io.Copy(f, resp.Body)
	if err != nil {
		return fmt.Errorf("failed to download %s to %s: %s", url, filename, err)
	}
	return nil
}
Example #11
0
func (o *mysqlOpener) Open(t testing.TB) (*Orm, interface{}) {
	// Check if MySQL is running
	conn, err := net.Dial("tcp", "localhost:3306")
	if err != nil {
		t.Skipf("MySQL is not running, skipping test (%v)", err)
	}
	conn.Close()
	creds := os.Getenv("GONDOLA_ORM_MYSQL_CREDENTIALS")
	if creds == "" {
		creds = "gotest:gotest"
	}
	orm := newOrm(t, "mysql://"+creds+"@/", true)
	db := orm.SqlDB()
	if _, err := db.Exec("DROP DATABASE IF EXISTS gotest"); err != nil {
		t.Skipf("cannot connect to mysql database, skipping test: %s", err)
	}
	if _, err := db.Exec("CREATE DATABASE gotest"); err != nil {
		t.Fatal(err)
	}
	if err := orm.Close(); err != nil {
		t.Fatal(err)
	}
	return newOrm(t, "mysql://"+creds+"@/gotest", true), nil
}
// testClient returns a *Client connected to a localy running sftp-server
// the *exec.Cmd returned must be defer Wait'd.
func testClient(t testing.TB, readonly bool) (*Client, *exec.Cmd) {
	if !*testIntegration {
		t.Skip("skipping intergration test")
	}
	cmd := exec.Command(*testSftp, "-e", "-R", "-l", debuglevel) // log to stderr, read only
	if !readonly {
		cmd = exec.Command(*testSftp, "-e", "-l", debuglevel) // log to stderr
	}
	cmd.Stderr = os.Stdout
	pw, err := cmd.StdinPipe()
	if err != nil {
		t.Fatal(err)
	}
	pr, err := cmd.StdoutPipe()
	if err != nil {
		t.Fatal(err)
	}
	if err := cmd.Start(); err != nil {
		t.Skipf("could not start sftp-server process: %v", err)
	}

	sftp, err := NewClientPipe(pr, pw)
	if err != nil {
		t.Fatal(err)
	}

	if err := sftp.sendInit(); err != nil {
		defer cmd.Wait()
		t.Fatal(err)
	}
	if err := sftp.recvVersion(); err != nil {
		defer cmd.Wait()
		t.Fatal(err)
	}
	return sftp, cmd
}
func skipWindows(t testing.TB) {
	if runtime.GOOS == "windows" {
		t.Skipf("Skipping test on %s", runtime.GOOS)
	}
}
Example #14
0
func requiresCommand(t testing.TB, cmd string) {
	if _, err := exec.LookPath(cmd); err != nil {
		t.Skipf("required executable %s not found", cmd)
	}
}
func testCheckAvailable(tb testing.TB) {
	_, err := exec.LookPath(testExecutable)
	if err != nil {
		tb.Skipf("GraphicsMagick is not available: %s", err)
	}
}