Skip to content

Commit a984d37

Browse files
author
shabtaisharon
authored
Merge pull request #57 from RachelTucker/travis
Adding travis yml and updating tests to work with go test
2 parents 24b2582 + 5dafaa2 commit a984d37

File tree

10 files changed

+89
-24
lines changed

10 files changed

+89
-24
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: go
2+
3+
go:
4+
- 1.8.x
5+
- 1.9.x
6+
- master
7+
8+
go_import_path: spectra/ds3_go_sdk
9+
10+
script:
11+
- go test ./ds3

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ In the ds3_go_sdk you create a `Client` instance through the setting of the foll
5252

5353
Examples
5454
--------
55-
All examples are listed in the [samples](samples/) module.
55+
All examples are listed in the [samples](samples/) module. All samples can be run from [samples main](samples/samples.go).
5656

57-
* [How to use get service to list buckets](samples/getServiceSample.go)
58-
* [How to create a bucket](samples/getBucketSample.go)
59-
* [How to get a single object using a naked S3 get](samples/getObjectSample.go)
60-
* [How to use bulk put to send multiple files to the BP efficiently](samples/putBulkSample.go)
61-
* [How to use bulk get to retrieve multiple files from the BP efficiently](samples/getBulkSample.go)
57+
* [How to use get service to list buckets](samples/functions/getServiceSample.go)
58+
* [How to create a bucket](samples/functions/getBucketSample.go)
59+
* [How to get a single object using a naked S3 get](samples/functions/getObjectSample.go)
60+
* [How to use bulk put to send multiple files to the BP efficiently](samples/functions/putBulkSample.go)
61+
* [How to use bulk get to retrieve multiple files from the BP efficiently](samples/functions/getBulkSample.go)
6262

6363
Running Tests with GB
6464
---------------------

ds3/ds3Client_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,19 +834,19 @@ func TestDeleteObjects(t *testing.T) {
834834
}
835835

836836
if response.DeleteResult.DeletedObjects == nil {
837-
t.Fatalf("Expected '%s' but got 'nil'", expectedDeleted)
837+
t.Fatalf("Expected '%v' but got 'nil'", expectedDeleted)
838838
}
839839

840840
if !reflect.DeepEqual(response.DeleteResult.DeletedObjects, expectedDeleted) {
841-
t.Fatalf("Expected '%s' but got '%s'", expectedDeleted, response.DeleteResult.DeletedObjects)
841+
t.Fatalf("Expected '%v' but got '%v'", expectedDeleted, response.DeleteResult.DeletedObjects)
842842
}
843843

844844
if response.DeleteResult.Errors == nil {
845-
t.Fatalf("Expected '%s' but got 'nil'", expectedErrors)
845+
t.Fatalf("Expected '%v' but got 'nil'", expectedErrors)
846846
}
847847

848848
if !reflect.DeepEqual(response.DeleteResult.Errors, expectedErrors) {
849-
t.Fatalf("Expected '%s' but got '%s'", expectedErrors, response.DeleteResult.Errors)
849+
t.Fatalf("Expected '%v' but got '%v'", expectedErrors, response.DeleteResult.Errors)
850850
}
851851
}
852852

@@ -1393,7 +1393,7 @@ func TestGetTapesSpectraS3(t *testing.T) {
13931393
ds3Testing.AssertStringPtrIsNil(t, "LastVerified", tape.LastVerified)
13941394
ds3Testing.AssertNonNilStringPtr(t, "PartitionId", "4f8a5cbb-9837-41d9-afd1-cebed41f18f7", tape.PartitionId)
13951395
if tape.PreviousState != nil {
1396-
t.Fatalf("Expected previous state '%d' but was '%d'.", "nil", *tape.PreviousState)
1396+
t.Fatalf("Expected previous state '%s' but was '%s'.", "nil", tape.PreviousState.String())
13971397
}
13981398
ds3Testing.AssertNonNilStringPtr(t, "SerialNumber", "HP-W130501213", tape.SerialNumber)
13991399
ds3Testing.AssertString(t, "State", models.TAPE_STATE_NORMAL.String(), tape.State.String())
@@ -1459,7 +1459,7 @@ func TestGetTapeSpectraS3(t *testing.T) {
14591459
ds3Testing.AssertStringPtrIsNil(t, "LastVerified", tape.LastVerified)
14601460
ds3Testing.AssertNonNilStringPtr(t, "PartitionId", "4f8a5cbb-9837-41d9-afd1-cebed41f18f7", tape.PartitionId)
14611461
if tape.PreviousState != nil {
1462-
t.Fatalf("Expected previous state '%d' but was '%d'.", "nil", *tape.PreviousState)
1462+
t.Fatalf("Expected previous state '%s' but was '%s'.", "nil", tape.PreviousState.String())
14631463
}
14641464
ds3Testing.AssertNonNilStringPtr(t, "SerialNumber", "HP-W130501213", tape.SerialNumber)
14651465
ds3Testing.AssertString(t, "State", models.TAPE_STATE_NORMAL.String(), tape.State.String())

samples/getBucketSample.go renamed to samples/functions/getBucketSample.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
// specific language governing permissions and limitations under the License.
1111

12-
package main
12+
package functions
1313

1414
import (
1515
"log"
@@ -21,7 +21,9 @@ import (
2121

2222
// Demonstrates how to get a list of S3 objects in a bucket. Assumes that the target
2323
// bucket already exists and has files, i.e. run putBulkSample.go first.
24-
func main() {
24+
func GetBucketSample() {
25+
fmt.Println("---- Get Bucket Sample ----")
26+
2527
// Create the client from environment variables.
2628
client, err := buildclient.FromEnv()
2729
if err != nil {

samples/getBulkSample.go renamed to samples/functions/getBulkSample.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
// specific language governing permissions and limitations under the License.
1111

12-
package main
12+
package functions
1313

1414
import (
1515
"spectra/ds3_go_sdk/ds3/buildclient"
1616
"log"
1717
"spectra/ds3_go_sdk/ds3/models"
1818
"spectra/ds3_go_sdk/samples/utils"
1919
"time"
20+
"fmt"
2021
)
2122

2223
// Demonstrates how to perform a bulk get. Assumes that the target bucket already exists
2324
// and has files, i.e. run putBulkSample.go first.
24-
func main() {
25+
func GetBulkSample() {
26+
fmt.Println("---- Get Bulk Sample ----")
27+
2528
// Create a client from environment variables.
2629
client, err := buildclient.FromEnv()
2730
if err != nil {
@@ -87,6 +90,7 @@ func main() {
8790
if err != nil {
8891
log.Fatal(err)
8992
}
93+
fmt.Printf("Retrived: %s offset=%d length%d\n", *curObj.Name, curObj.Offset, curObj.Length)
9094
}
9195
curChunkCount++
9296
}

samples/getObjectSample.go renamed to samples/functions/getObjectSample.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
// specific language governing permissions and limitations under the License.
1111

12-
package main
12+
package functions
1313

1414
import (
1515
"log"
1616
"spectra/ds3_go_sdk/ds3/models"
1717
"spectra/ds3_go_sdk/ds3/buildclient"
1818
"spectra/ds3_go_sdk/samples/utils"
19+
"fmt"
1920
)
2021

2122
// Demonstrates how to get an object within a bucket. Assumes that the
2223
// target bucket already exists and has the specified file.
2324
// i.e. run putBulkSample.go first.
24-
func main() {
25+
func GetObjectSample() {
26+
fmt.Println("---- Get Object Sample ----")
27+
2528
// Create the client from environment variables.
2629
client, err := buildclient.FromEnv()
2730
if err != nil {
@@ -37,4 +40,5 @@ func main() {
3740

3841
// Verify that the contents of the book were retrieved correctly.
3942
utils.VerifyBookContent(utils.BookNames[0], getObjResponse.Content)
43+
fmt.Printf("Retrieved: %s\n", utils.BookNames[0])
4044
}

samples/getServiceSample.go renamed to samples/functions/getServiceSample.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
// specific language governing permissions and limitations under the License.
1111

12-
package main
12+
package functions
1313

1414
import (
1515
"log"
@@ -19,7 +19,9 @@ import (
1919
"spectra/ds3_go_sdk/samples/utils"
2020
)
2121

22-
func main() {
22+
func GetServiceSample() {
23+
fmt.Println("---- Get Service Sample ----")
24+
2325
// Create the client from environment variables.
2426
client, err := buildclient.FromEnv()
2527
if err != nil {

samples/putBulkSample.go renamed to samples/functions/putBulkSample.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1010
// specific language governing permissions and limitations under the License.
1111

12-
package main
12+
package functions
1313

1414
import (
1515
"log"
@@ -18,9 +18,12 @@ import (
1818
"os"
1919
"time"
2020
"spectra/ds3_go_sdk/samples/utils"
21+
"fmt"
2122
)
2223

23-
func main() {
24+
func PutBulkSample() {
25+
fmt.Println("---- Put Bulk Sample ----")
26+
2427
// Create a client from environment variables.
2528
client, err := buildclient.FromEnv()
2629
if err != nil {
@@ -87,14 +90,15 @@ func main() {
8790
log.Fatal(err)
8891
}
8992

90-
putObjRequest := models.NewPutObjectRequest(utils.BucketName, *curObj.Name, *reader).
93+
putObjRequest := models.NewPutObjectRequest(utils.BucketName, *curObj.Name, reader).
9194
WithJob(chunksReadyResponse.MasterObjectList.JobId).
9295
WithOffset(curObj.Offset)
9396

9497
_, err = client.PutObject(putObjRequest)
9598
if err != nil {
9699
log.Fatal(err)
97100
}
101+
fmt.Printf("Sent: %s offset=%d length=%d\n", *curObj.Name, curObj.Offset, curObj.Length)
98102
}
99103
curChunkCount++
100104
}

samples/samples.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use
3+
// this file except in compliance with the License. A copy of the License is located at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// or in the "license" file accompanying this file.
8+
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
// specific language governing permissions and limitations under the License.
11+
12+
package main
13+
14+
import "spectra/ds3_go_sdk/samples/functions"
15+
16+
// Runs the various sample code. Each sample is self contained and can be run separately.
17+
func main() {
18+
19+
// Lists all existing buckets on the BP.
20+
// Source code: getServiceSample.go
21+
functions.GetServiceSample()
22+
23+
// Creates a bucket on the BP and puts sample files in the bucket.
24+
// Source code: putBulkSample.go
25+
functions.PutBulkSample()
26+
27+
// Gets a list of S3 objects in a bucket.
28+
// Source code: getBucketSample.go
29+
functions.GetBucketSample()
30+
31+
// Retrieve an object from a bucket.
32+
// Source code: getObjectSample.go
33+
functions.GetObjectSample()
34+
35+
// Retrieves several objects from a bucket on the BP.
36+
// Source code: getBulkSample.go
37+
functions.GetBulkSample()
38+
}

samples/utils/sampleUtils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
const BucketName = "GoPutBulkBucket"
25-
const ResourceFolder = "./src/samples/resources/"
25+
const ResourceFolder = "./samples/resources/"
2626
var BookNames = []string{"beowulf.txt", "sherlock_holmes.txt", "tale_of_two_cities.txt", "ulysses.txt"}
2727

2828
// Loads a book from resources folder.

0 commit comments

Comments
 (0)