forked from kanisterio/kanister
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement kando location push/pull (kanisterio#3183)
* Implement kando location push/pull * Swallow errors on close
- Loading branch information
Showing
5 changed files
with
138 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kando | ||
|
||
import ( | ||
"testing" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
// Hook up gocheck into the "go test" runner. | ||
func Test(t *testing.T) { TestingT(t) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package kando | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
. "gopkg.in/check.v1" | ||
|
||
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1" | ||
"github.com/kanisterio/kanister/pkg/location" | ||
"github.com/kanisterio/kanister/pkg/param" | ||
) | ||
|
||
type LocationSuite struct{} | ||
|
||
var _ = Suite(&LocationSuite{}) | ||
|
||
const testBucketName = "S3_TEST_BUCKET" | ||
|
||
var objectStoreTestEnvVars []string = []string{ | ||
location.AWSAccessKeyID, | ||
location.AWSSecretAccessKey, | ||
testBucketName, | ||
} | ||
|
||
const testContent = "test-content" | ||
|
||
func (s *LocationSuite) TestLocationObjectStore(c *C) { | ||
skipIfEnvNotSet(c, objectStoreTestEnvVars) | ||
ctx := context.Background() | ||
p := ¶m.Profile{ | ||
Location: crv1alpha1.Location{ | ||
Type: crv1alpha1.LocationTypeS3Compliant, | ||
S3Compliant: &crv1alpha1.S3CompliantLocation{ | ||
Bucket: os.Getenv(testBucketName), | ||
Prefix: c.TestName(), | ||
}, | ||
}, | ||
Credential: param.Credential{ | ||
Type: param.CredentialTypeKeyPair, | ||
KeyPair: ¶m.KeyPair{ | ||
ID: os.Getenv(location.AWSAccessKeyID), | ||
Secret: os.Getenv(location.AWSSecretAccessKey), | ||
}, | ||
}, | ||
} | ||
path := filepath.Join(c.MkDir(), "test-object.txt") | ||
|
||
source := bytes.NewBufferString(testContent) | ||
err := locationPush(ctx, p, path, source) | ||
c.Assert(err, IsNil) | ||
|
||
target := bytes.NewBuffer(nil) | ||
err = locationPull(ctx, p, path, target) | ||
c.Assert(err, IsNil) | ||
c.Assert(target.String(), Equals, testContent) | ||
} | ||
|
||
func skipIfEnvNotSet(c *C, envVars []string) { | ||
for _, ev := range envVars { | ||
if os.Getenv(ev) == "" { | ||
reason := fmt.Sprintf("Test %s requires the environemnt variable '%s'", c.TestName(), ev) | ||
c.Skip(reason) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters