Skip to content

Commit

Permalink
fix: run as application user to set the proper permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Niccolò Fei <[email protected]>
  • Loading branch information
NiccoloFei committed Oct 8, 2024
1 parent a3143ef commit fa5a098
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
23 changes: 4 additions & 19 deletions tests/e2e/asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,8 @@ func AssertCreateTestDataLargeObject(namespace, clusterName string, oid int, dat
query := fmt.Sprintf("CREATE TABLE IF NOT EXISTS image (name text,raster oid); "+
"INSERT INTO image (name, raster) VALUES ('beautiful image', lo_from_bytea(%d, '%s'));", oid, data)

primaryPod, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())
_, _, err = env.ExecQueryInInstancePod(
testsUtils.PodLocator{
Namespace: primaryPod.Namespace,
PodName: primaryPod.Name,
},
testsUtils.AppDBName,
query)
_, err := testsUtils.RunExecOverForward(env, namespace, clusterName, testsUtils.AppDBName,
apiv1.ApplicationUserSecretSuffix, query)
Expect(err).ToNot(HaveOccurred())
})
}
Expand Down Expand Up @@ -1238,16 +1231,8 @@ func AssertFastFailOver(
", PRIMARY KEY (id)" +
")"

primaryPod, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())

_, _, err = env.ExecQueryInInstancePod(
testsUtils.PodLocator{
Namespace: primaryPod.Namespace,
PodName: primaryPod.Name,
},
testsUtils.AppDBName,
query)
_, err = testsUtils.RunExecOverForward(env, namespace, clusterName, testsUtils.AppDBName,
apiv1.ApplicationUserSecretSuffix, query)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
9 changes: 2 additions & 7 deletions tests/e2e/cluster_microservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,8 @@ func assertImportRenamesSelectedDatabase(
By(fmt.Sprintf("creating table '%s' and insert records on selected db %v", tableName, dbToImport), func() {
// create a table with two records
query := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s AS VALUES (1),(2);", tableName)
_, _, err = env.ExecQueryInInstancePod(
testsUtils.PodLocator{
Namespace: primaryPod.Namespace,
PodName: primaryPod.Name,
},
testsUtils.DatabaseName(dbToImport),
query)
_, err = testsUtils.RunExecOverForward(env, namespace, clusterName, dbToImport,
apiv1.ApplicationUserSecretSuffix, query)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
13 changes: 3 additions & 10 deletions tests/e2e/fastswitchover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"

apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
"github.com/cloudnative-pg/cloudnative-pg/tests"
"github.com/cloudnative-pg/cloudnative-pg/tests/utils"

Expand Down Expand Up @@ -134,16 +135,8 @@ func assertFastSwitchover(namespace, sampleFile, clusterName, webTestFile, webTe
", PRIMARY KEY (id)" +
")"

primaryPod, err := env.GetClusterPrimary(namespace, clusterName)
Expect(err).ToNot(HaveOccurred())

_, _, err = env.ExecQueryInInstancePod(
utils.PodLocator{
Namespace: primaryPod.Namespace,
PodName: primaryPod.Name,
},
utils.AppDBName,
query)
_, err := utils.RunExecOverForward(env, namespace, clusterName, utils.AppDBName,
apiv1.ApplicationUserSecretSuffix, query)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
29 changes: 28 additions & 1 deletion tests/utils/psql_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func ForwardPSQLConnectionWithCreds(
return forward, conn, err
}

// RunQueryRowOverForward runs QueryRow with a given query, returning the result Row
// RunQueryRowOverForward runs QueryRow with a given query, returning the Row of the SQL command
func RunQueryRowOverForward(
env *TestingEnvironment,
namespace,
Expand All @@ -226,3 +226,30 @@ func RunQueryRowOverForward(

return conn.QueryRow(query), nil
}

// RunExecOverForward runs Exec with a given query, returning the Result of the SQL command
func RunExecOverForward(
env *TestingEnvironment,
namespace,
clusterName,
dbname,
secretSuffix,
query string,
) (sql.Result, error) {
forward, conn, err := ForwardPSQLConnection(
env,
namespace,
clusterName,
dbname,
secretSuffix,
)
if err != nil {
return nil, err
}
defer func() {
_ = conn.Close()
forward.Close()
}()

return conn.Exec(query)
}

0 comments on commit fa5a098

Please sign in to comment.