-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Refactors resource tests to use GetClusterInfo federated_database_instance
#2412
Changes from all commits
e11cf69
281e5eb
483fdd4
3c81ace
98d29d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,29 @@ import ( | |
|
||
type ClusterRequest struct { | ||
Tags map[string]string | ||
ProjectID string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would favour defining as a pointer so it is clear that property is optional, however I see the same applies to all other properties in this struct. Maybe a comment top level of the struct clarifying all properties are optional can be an option as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would keep strings (with empty being optional), but agree a comment can help There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! |
||
ResourceSuffix string | ||
ResourceDependencyName string | ||
ClusterNameExplicit string | ||
ClusterName string | ||
ReplicationSpecs []ReplicationSpecRequest | ||
DiskSizeGb int | ||
CloudBackup bool | ||
Geosharded bool | ||
PitEnabled bool | ||
} | ||
|
||
func (r *ClusterRequest) AddDefaults() { | ||
if r.ResourceSuffix == "" { | ||
r.ResourceSuffix = defaultClusterResourceSuffix | ||
} | ||
if len(r.ReplicationSpecs) == 0 { | ||
r.ReplicationSpecs = []ReplicationSpecRequest{{}} | ||
} | ||
if r.ClusterName == "" { | ||
r.ClusterName = RandomClusterName() | ||
} | ||
} | ||
|
||
type ClusterInfo struct { | ||
ProjectIDStr string | ||
ProjectID string | ||
|
@@ -29,6 +43,8 @@ type ClusterInfo struct { | |
ClusterTerraformStr string | ||
} | ||
|
||
const defaultClusterResourceSuffix = "cluster_info" | ||
|
||
// GetClusterInfo is used to obtain a project and cluster configuration resource. | ||
// When `MONGODB_ATLAS_CLUSTER_NAME` and `MONGODB_ATLAS_PROJECT_ID` are defined, creation of resources is avoided. This is useful for local execution but not intended for CI executions. | ||
// Clusters will be created in project ProjectIDExecution. | ||
|
@@ -37,26 +53,26 @@ func GetClusterInfo(tb testing.TB, req *ClusterRequest) ClusterInfo { | |
if req == nil { | ||
req = new(ClusterRequest) | ||
} | ||
clusterName := os.Getenv("MONGODB_ATLAS_CLUSTER_NAME") | ||
projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") | ||
if clusterName != "" && projectID != "" { | ||
return ClusterInfo{ | ||
ProjectIDStr: fmt.Sprintf("%q", projectID), | ||
ProjectID: projectID, | ||
ClusterName: clusterName, | ||
ClusterNameStr: fmt.Sprintf("%q", clusterName), | ||
ClusterTerraformStr: "", | ||
if req.ProjectID == "" { | ||
if ExistingClusterUsed() { | ||
projectID, clusterName := existingProjectIDClusterName() | ||
return ClusterInfo{ | ||
ProjectIDStr: fmt.Sprintf("%q", projectID), | ||
ProjectID: projectID, | ||
ClusterName: clusterName, | ||
ClusterNameStr: fmt.Sprintf("%q", clusterName), | ||
ClusterTerraformStr: "", | ||
} | ||
} | ||
req.ProjectID = ProjectIDExecution(tb) | ||
} | ||
projectID = ProjectIDExecution(tb) | ||
clusterTerraformStr, clusterName, err := ClusterResourceHcl(projectID, req) | ||
clusterTerraformStr, clusterName, clusterResourceName, err := ClusterResourceHcl(req) | ||
if err != nil { | ||
tb.Error(err) | ||
} | ||
clusterResourceName := "mongodbatlas_advanced_cluster.cluster_info" | ||
return ClusterInfo{ | ||
ProjectIDStr: fmt.Sprintf("%q", projectID), | ||
ProjectID: projectID, | ||
ProjectIDStr: fmt.Sprintf("%q", req.ProjectID), | ||
ProjectID: req.ProjectID, | ||
ClusterName: clusterName, | ||
ClusterNameStr: fmt.Sprintf("%s.name", clusterResourceName), | ||
ClusterResourceName: clusterResourceName, | ||
|
@@ -65,11 +81,14 @@ func GetClusterInfo(tb testing.TB, req *ClusterRequest) ClusterInfo { | |
} | ||
|
||
func ExistingClusterUsed() bool { | ||
clusterName := os.Getenv("MONGODB_ATLAS_CLUSTER_NAME") | ||
projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") | ||
projectID, clusterName := existingProjectIDClusterName() | ||
return clusterName != "" && projectID != "" | ||
} | ||
|
||
func existingProjectIDClusterName() (projectID, clusterName string) { | ||
return os.Getenv("MONGODB_ATLAS_PROJECT_ID"), os.Getenv("MONGODB_ATLAS_CLUSTER_NAME") | ||
} | ||
|
||
type ReplicationSpecRequest struct { | ||
ZoneName string | ||
Region string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to another PR, what about pass clusterInfo to configWithCluster?