<commit_before>// Copyright 2014-2017 Spectra Logic Corporation. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use
// this file except in compliance with the License. A copy of the License is located at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// or in the "license" file accompanying this file.
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

package ds3_integration

import (
    "testing"
    "log"
    "os"
    "ds3"
    "ds3/models"
    "ds3_integration/utils"
    "io/ioutil"
    "bytes"
    "ds3_utils/ds3Testing"
    "strconv"
)

var client *ds3.Client
var testBucket = "GoIntegrationTestBucket"

func TestMain(m *testing.M) {
    var err error
    var exitVal int
    client, err = testutils.SetupTestEnv(testBucket)
    if err != nil {
        log.Printf("Unable to setup test environment '%s'.", err.Error())
        exitVal = 1
    } else {
        exitVal = m.Run()
    }
    testutils.TeardownTestEnv(client, testBucket)
    os.Exit(exitVal)
}

func TestGetService(t *testing.T) {
    response, err := client.GetService(models.NewGetServiceRequest())
    ds3Testing.AssertNilError(t, err)
    if response == nil {
        t.Fatal("Received an unexpected nil response.")
    }
}

func TestBucket(t *testing.T) {
    //Create bucket
    bucketName := "GoTestPutBucket"
    putErr := testutils.PutBucketLogError(t, client, bucketName)
    ds3Testing.AssertNilError(t, putErr)
    defer testutils.DeleteBucketLogError(t, client, bucketName)

    //Verify that bucket exists
    getBucketResponse, getErr := testutils.GetBucketLogError(t, client, bucketName)
    ds3Testing.AssertNilError(t, getErr)
    ds3Testing.AssertNonNilStringPtr(t, "Name", bucketName, getBucketResponse.ListBucketResult.Name)
}

func TestObject(t *testing.T) {
    testutils.DeleteBucketContents(client, testBucket)
    beowulf := "beowulf.txt"

    //Put object to BP
    book, bookErr := testutils.LoadBookLogError(t, beowulf)
    ds3Testing.AssertNilError(t, bookErr)
    defer testutils.DeleteObjectLogError(t, client, testBucket, beowulf)

    putObjErr := testutils.PutObjectLogError(t, client, testBucket, beowulf, book)
    ds3Testing.AssertNilError(t, putObjErr)

    //Verify that object exists
    getObjectResponse, getObjErr := testutils.GetObjectLogError(t, client, testBucket, beowulf)
    if getObjErr != nil {
        defer getObjectResponse.Content.Close()<commit_msg>Adding missing defer<commit_after>// Copyright 2014-2017 Spectra Logic Corporation. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use
// this file except in compliance with the License. A copy of the License is located at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// or in the "license" file accompanying this file.
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

package ds3_integration

import (
    "testing"
    "log"
    "os"
    "ds3"
    "ds3/models"
    "ds3_integration/utils"
    "io/ioutil"
    "bytes"
    "ds3_utils/ds3Testing"
    "strconv"
)

var client *ds3.Client
var testBucket = "GoIntegrationTestBucket"

func TestMain(m *testing.M) {
    var err error
    var exitVal int
    client, err = testutils.SetupTestEnv(testBucket)
    if err != nil {
        log.Printf("Unable to setup test environment '%s'.", err.Error())
        exitVal = 1
    } else {
        exitVal = m.Run()
    }
    testutils.TeardownTestEnv(client, testBucket)
    os.Exit(exitVal)
}

func TestGetService(t *testing.T) {
    response, err := client.GetService(models.NewGetServiceRequest())
    ds3Testing.AssertNilError(t, err)
    if response == nil {
        t.Fatal("Received an unexpected nil response.")
    }
}

func TestBucket(t *testing.T) {
    //Create bucket
    bucketName := "GoTestPutBucket"
    putErr := testutils.PutBucketLogError(t, client, bucketName)
    ds3Testing.AssertNilError(t, putErr)
    defer testutils.DeleteBucketLogError(t, client, bucketName)

    //Verify that bucket exists
    getBucketResponse, getErr := testutils.GetBucketLogError(t, client, bucketName)
    ds3Testing.AssertNilError(t, getErr)
    ds3Testing.AssertNonNilStringPtr(t, "Name", bucketName, getBucketResponse.ListBucketResult.Name)
}

func TestObject(t *testing.T) {
    defer testutils.DeleteBucketContents(client, testBucket)
    beowulf := "beowulf.txt"

    //Put object to BP
    book, bookErr := testutils.LoadBookLogError(t, beowulf)
    ds3Testing.AssertNilError(t, bookErr)
    defer testutils.DeleteObjectLogError(t, client, testBucket, beowulf)

    putObjErr := testutils.PutObjectLogError(t, client, testBucket, beowulf, book)
    ds3Testing.AssertNilError(t, putObjErr)

    //Verify that object exists
    getObjectResponse, getObjErr := testutils.GetObjectLogError(t, client, testBucket, beowulf)
    if getObjErr != nil {
        defer getObjectResponse.Content.Close()
{'fraction_non_alphanumeric': 0.10299446881556361, 'fraction_numerical': 0.009917985885943162, 'mean_word_length': 3.624338624338624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5811188', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1603, 'n_words': 448}