mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
test: fix clear env on s3 tests
This commit is contained in:
parent
661f56ac15
commit
235fff7b8a
@ -4,14 +4,15 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setEnv() {
|
func setEnv() {
|
||||||
@ -19,6 +20,13 @@ func setEnv() {
|
|||||||
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
|
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearnEnv() {
|
||||||
|
os.Unsetenv("AWS_ACCESS_KEY_ID")
|
||||||
|
os.Unsetenv("AWS_SECRET_ACCESS_KEY")
|
||||||
|
os.Unsetenv("AWS_SHARED_CREDENTIALS_FILE")
|
||||||
|
os.Unsetenv("AWS_CONFIG_FILE")
|
||||||
|
}
|
||||||
|
|
||||||
func Test_awsSession(t *testing.T) {
|
func Test_awsSession(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
profile string
|
profile string
|
||||||
@ -55,7 +63,7 @@ func Test_awsSession(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "test default shared credentials provider",
|
name: "test default shared credentials provider",
|
||||||
before: func() {
|
before: func() {
|
||||||
os.Clearenv()
|
clearnEnv()
|
||||||
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
||||||
},
|
},
|
||||||
expectToken: "token",
|
expectToken: "token",
|
||||||
@ -63,7 +71,7 @@ func Test_awsSession(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "test default shared credentials provider",
|
name: "test default shared credentials provider",
|
||||||
before: func() {
|
before: func() {
|
||||||
os.Clearenv()
|
clearnEnv()
|
||||||
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
||||||
},
|
},
|
||||||
expectToken: "token",
|
expectToken: "token",
|
||||||
@ -71,7 +79,7 @@ func Test_awsSession(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "test profile with shared credentials provider",
|
name: "test profile with shared credentials provider",
|
||||||
before: func() {
|
before: func() {
|
||||||
os.Clearenv()
|
clearnEnv()
|
||||||
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
@ -83,8 +91,8 @@ func Test_awsSession(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
os.Clearenv()
|
clearnEnv()
|
||||||
defer os.Clearenv()
|
defer clearnEnv()
|
||||||
if tt.before != nil {
|
if tt.before != nil {
|
||||||
tt.before()
|
tt.before()
|
||||||
}
|
}
|
||||||
@ -130,8 +138,8 @@ const assumeRoleRespMsg = `
|
|||||||
`
|
`
|
||||||
|
|
||||||
func Test_awsSession_mfa(t *testing.T) {
|
func Test_awsSession_mfa(t *testing.T) {
|
||||||
os.Clearenv()
|
clearnEnv()
|
||||||
defer os.Clearenv()
|
defer clearnEnv()
|
||||||
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
os.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join("testdata", "credentials.ini"))
|
||||||
os.Setenv("AWS_CONFIG_FILE", filepath.Join("testdata", "config.ini"))
|
os.Setenv("AWS_CONFIG_FILE", filepath.Join("testdata", "config.ini"))
|
||||||
|
|
||||||
@ -180,8 +188,8 @@ func Test_awsSession_fail(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
os.Clearenv()
|
clearnEnv()
|
||||||
defer os.Clearenv()
|
defer clearnEnv()
|
||||||
|
|
||||||
builder := newSessionBuilder()
|
builder := newSessionBuilder()
|
||||||
sess := builder.Build()
|
sess := builder.Build()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user