Skip to content

Commit

Permalink
acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterp committed Aug 28, 2023
1 parent 5f1de68 commit aa55b22
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ completions:
.PHONY: clean
clean::
$(RM) contrib/completion manpage $(OAS_FILE)

test-acc: build
cd internal/integration-testing/sos
go test -test.v
84 changes: 47 additions & 37 deletions internal/integration-testing/sos/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"io/ioutil"

Check failure on line 7 in internal/integration-testing/sos/main_test.go

View workflow job for this annotation

GitHub Actions / build

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"math/rand"
"os"
"os/exec"
"strings"
Expand All @@ -27,26 +29,26 @@ type SOSSuite struct {

PrepDir string
DownloadDir string

ObjectList []string

S3Client *s3.Client
}

func (s *SOSSuite) SetupTest() {
// TODO introduce a TF_ACC like test guard
ctx := context.Background()

// TODO build the cli
// if err := exec.Command("go", "build").Run(); err != nil {
// fmt.Println("Error building CLI:", err)
// return
// }
var err error

// Create test and download directories
if err := os.MkdirAll(s.PrepDir, 0755); err != nil {
fmt.Println("Error creating test directory:", err)
return
}
if err := os.MkdirAll(s.DownloadDir, 0755); err != nil {
fmt.Println("Error creating download directory:", err)
return
}
tmpDirPrefix := "exo-cli-acc-tests"
prepDir, err := ioutil.TempDir("", tmpDirPrefix)
s.Assert().NoError(err)
s.PrepDir = prepDir + "/"

downloadDir, err := ioutil.TempDir("", tmpDirPrefix)
s.Assert().NoError(err)
s.DownloadDir = downloadDir + "/"

var caCerts io.Reader

Expand All @@ -57,7 +59,7 @@ func (s *SOSSuite) SetupTest() {

config.WithEndpointResolver(aws.EndpointResolverFunc(
func(service, region string) (aws.Endpoint, error) {
sosURL := strings.Replace("https://sos-{zone}.exo.io", "{zone}", zone, 1)
sosURL := fmt.Sprintf("https://sos-%s.exo.io", zone)
return aws.Endpoint{
URL: sosURL,
SigningRegion: zone,
Expand All @@ -68,39 +70,46 @@ func (s *SOSSuite) SetupTest() {
)...)
s.Assert().NoError(err)

// TODO assert that bucket doesn't exist
//
// TODO create bucket
// input := &s3.CreateBucketInput{
// Bucket: &bucketName,
// }

// TODO enable versioning
input := &s3.CreateBucketInput{
Bucket: &s.BucketName,
}

_ = s3.NewFromConfig(cfg)
//svc := s3.NewFromConfig(cfg)
// _, err = svc.CreateBucket(ctx, input)
s.S3Client = s3.NewFromConfig(cfg)
_, err = s.S3Client.CreateBucket(ctx, input)
s.Assert().NoError(err)
}

func (s *SOSSuite) TearDownTest() {
if err := os.RemoveAll(s.PrepDir); err != nil {
fmt.Println("Error cleaning up test directory:", err)
var (
err error
ctx context.Context = context.Background()
)

for _, v := range s.ObjectList {
s.S3Client.DeleteObject(ctx, &s3.DeleteObjectInput{

Check failure on line 89 in internal/integration-testing/sos/main_test.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `s.S3Client.DeleteObject` is not checked (errcheck)
Bucket: &s.BucketName,
Key: &v,
})
}

if err := os.RemoveAll(s.DownloadDir); err != nil {
fmt.Println("Error cleaning up download directory:", err)
}
_, err = s.S3Client.DeleteBucket(ctx, &s3.DeleteBucketInput{
Bucket: &s.BucketName,
})
s.Assert().NoError(err)

err = os.RemoveAll(s.PrepDir)
s.Assert().NoError(err)

err = os.RemoveAll(s.DownloadDir)
s.Assert().NoError(err)
}

func TestSOSSuite(t *testing.T) {
integDir := "integdir/"
s := &SOSSuite{
BucketName: "integ-bucket",
ExoCLIExecutable: "../../../cli",
testBucketName := fmt.Sprintf("exo-cli-acc-tests-%d", rand.Int())

PrepDir: integDir + "prep/",
DownloadDir: integDir + "downloads/",
s := &SOSSuite{
BucketName: testBucketName,
ExoCLIExecutable: "../../../bin/exo",
}
suite.Run(t, s)
}
Expand Down Expand Up @@ -147,6 +156,7 @@ func (s *SOSSuite) writeFile(filename, content string) {

func (s *SOSSuite) uploadFile(filePath string) {
s.exo(fmt.Sprintf("storage upload %s %s", s.PrepDir+filePath, s.BucketName))
s.ObjectList = append(s.ObjectList, filePath)
}

func (s *SOSSuite) exo(args string) string {
Expand Down

0 comments on commit aa55b22

Please sign in to comment.