forked from hadenlabs/terraform-aws-iam-s3-user
-
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.
chore: implement code internal faker s3 (hadenlabs#3)
- Loading branch information
Showing
9 changed files
with
671 additions
and
65 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
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,19 @@ | ||
package faker | ||
|
||
import ( | ||
"github.com/lithammer/shortuuid/v3" | ||
) | ||
|
||
type FakeS3 interface { | ||
Name() string // Name server | ||
} | ||
|
||
type fakeS3 struct{} | ||
|
||
func Bucket() FakeS3 { | ||
return fakeS3{} | ||
} | ||
|
||
func (n fakeS3) Name() string { | ||
return shortuuid.New() | ||
} |
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,12 @@ | ||
package faker | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestS3FakeBucketName(t *testing.T) { | ||
name := Bucket().Name() | ||
assert.NotEmpty(t, name) | ||
} |
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,36 @@ | ||
package faker | ||
|
||
import ( | ||
"crypto/rand" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/lithammer/shortuuid/v3" | ||
|
||
"strings" | ||
|
||
"github.com/hadenlabs/terraform-aws-iam-s3-user/internal/errors" | ||
) | ||
|
||
type FakeServer interface { | ||
Name() string // Name server | ||
} | ||
|
||
type fakeServer struct{} | ||
|
||
func Server() FakeServer { | ||
return fakeServer{} | ||
} | ||
|
||
var ( | ||
names = []string{"optimusprime", "wheeljack", "bumblebee"} | ||
) | ||
|
||
func (n fakeServer) Name() string { | ||
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(names)))) | ||
if err != nil { | ||
panic(errors.New(errors.ErrorUnknown, err.Error())) | ||
} | ||
nameuuid := fmt.Sprintf("%s-%s", names[num.Int64()], shortuuid.New()) | ||
return strings.ToLower(nameuuid) | ||
} |
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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
package testutil | ||
|
||
// Server is the kind of error. | ||
type Server string | ||
|
||
// Servers Types. | ||
const ( | ||
Company Server = "evilcorp" | ||
Environment Server = "testing" | ||
Stage Server = "test" | ||
) |