Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kovayur committed Jun 13, 2023
1 parent fe02904 commit f1a4360
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
13 changes: 0 additions & 13 deletions fleetshard/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,17 @@ func TestSingleton_Failure(t *testing.T) {

func TestSingleton_Success_WhenManagedDBEnabled(t *testing.T) {
t.Setenv("CLUSTER_ID", "some-value")
t.Setenv("AWS_ROLE_ARN", "arn:aws:iam::012456789:role/fake_role")
t.Setenv("MANAGED_DB_ENABLED", "true")
t.Setenv("MANAGED_DB_SECURITY_GROUP", "some-group")
cfg, err := GetConfig()
require.NoError(t, err)
assert.Equal(t, cfg.AWS.RoleARN, "arn:aws:iam::012456789:role/fake_role")
assert.Equal(t, cfg.AWS.Region, "us-east-1")
assert.Equal(t, cfg.ManagedDB.Enabled, true)
assert.Equal(t, cfg.ManagedDB.SecurityGroup, "some-group")
}

func TestSingleton_Failure_WhenManagedDBEnabledAndAWSRoleArnNotSet(t *testing.T) {
t.Setenv("CLUSTER_ID", "some-value")
t.Setenv("MANAGED_DB_ENABLED", "true")
t.Setenv("MANAGED_DB_SECURITY_GROUP", "some-group")
cfg, err := GetConfig()
assert.Error(t, err, "MANAGED_DB_ENABLED == true and AWS_ROLE_ARN unset in the environment")
assert.Nil(t, cfg)
}

func TestSingleton_Failure_WhenManagedDBEnabledAndManagedDbSecurityGroupNotSet(t *testing.T) {
t.Setenv("CLUSTER_ID", "some-value")
t.Setenv("MANAGED_DB_ENABLED", "true")
t.Setenv("AWS_ROLE_ARN", "arn:aws:iam::012456789:role/fake_role")
cfg, err := GetConfig()
assert.Error(t, err, "MANAGED_DB_ENABLED == true and MANAGED_DB_SECURITY_GROUP unset in the environment")
assert.Nil(t, cfg)
Expand Down
10 changes: 6 additions & 4 deletions fleetshard/pkg/central/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,16 @@ func TestReconcileCreateWithLabelOperatorVersion(t *testing.T) {
}

func TestReconcileCreateWithManagedDBNoCredentials(t *testing.T) {
t.Setenv("AWS_ACCESS_KEY", "")
t.Setenv("AWS_SECRET_ACCESS_KEY", "")
t.Setenv("AWS_REGION", "us-east-1")
t.Setenv("AWS_ROLE_ARN", "arn:aws:iam::012456789:role/fake_role")
t.Setenv("AWS_WEB_IDENTITY_TOKEN_FILE", "/var/run/secrets/tokens/aws-token")

fakeClient := testutils.NewFakeClientBuilder(t).Build()

managedDBProvisioningClient, err := awsclient.NewRDSClient(
&config.Config{
AWS: config.AWS{
Region: "us-east-1",
RoleARN: "arn:aws:iam::012456789:role/fake_role",
},
ManagedDB: config.ManagedDB{
SecurityGroup: "security-group",
SubnetGroup: "db-group",
Expand Down

0 comments on commit f1a4360

Please sign in to comment.