Beispiel #1
0
// Will need a local valid google_storage_token.data file with read write access
// to run the below test.
func Auth_TestUploadWorkerArtifacts(t *testing.T) {
	client, err := auth.NewDefaultClient(true, auth.SCOPE_FULL_CONTROL)
	if err != nil {
		t.Errorf("Failed to authenticate: %s", err)
	}

	gs, err := NewGsUtil(client)
	if err != nil {
		t.Errorf("Unexpected error: %s", err)
	}
	testDir := "testupload"
	testPagesetType := "10ktest"
	StorageDir = "testdata"
	if err := gs.UploadWorkerArtifacts(testDir, testPagesetType, 1); err != nil {
		t.Errorf("Unexpected error: %s", err)
	}

	// Examine contents of the remote directory and then clean it up.
	service, err := storage.New(gs.client)
	if err != nil {
		t.Errorf("Unexpected error: %s", err)
	}
	gsDir := filepath.Join(testDir, testPagesetType, "slave1")
	resp, err := service.Objects.List(GSBucketName).Prefix(gsDir + "/").Do()
	if err != nil {
		t.Errorf("Unexpected error: %s", err)
	}
	assert.Equal(t, 3, len(resp.Items))
	for index, fileName := range []string{"TIMESTAMP", "alexa1-1.py", "alexa2-2.py"} {
		filePath := fmt.Sprintf("%s/%s", gsDir, fileName)
		defer util.LogErr(service.Objects.Delete(GSBucketName, filePath).Do())
		assert.Equal(t, filePath, resp.Items[index].Name)
	}
}
Beispiel #2
0
// Will need a local valid google_storage_token.data file with read write access
// to run the below test.
func Auth_TestDownloadWorkerArtifacts(t *testing.T) {
	testPagesetsDirName := filepath.Join("unit-tests", "util", "page_sets")

	client, err := auth.NewDefaultClient(true, auth.SCOPE_FULL_CONTROL)
	if err != nil {
		t.Errorf("Failed to authenticate: %s", err)
	}

	gs, err := NewGsUtil(client)
	if err != nil {
		t.Errorf("Unexpected error: %s", err)
	}

	tmpDir := filepath.Join(os.TempDir(), "util_test")
	StorageDir = tmpDir
	defer util.RemoveAll(tmpDir)
	if err := gs.DownloadWorkerArtifacts(testPagesetsDirName, "10k", 1); err != nil {
		t.Errorf("Unexpected error: %s", err)
	}

	// Examine contents of the local directory.
	localDir := filepath.Join(tmpDir, testPagesetsDirName, "10k")
	files, err := ioutil.ReadDir(localDir)
	if err != nil {
		t.Errorf("Unexpected error: %s", err)
	}
	assert.Equal(t, 3, len(files))
	assert.Equal(t, "TIMESTAMP", files[0].Name())
	assert.Equal(t, "alexa1-1.py", files[1].Name())
	assert.Equal(t, "alexa2-2.py", files[2].Name())
}