Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Increased unit test coverage #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

isaacdorfman
Copy link
Contributor

No description provided.

@bardielle
Copy link
Collaborator

The subsystem tests are broken... please fix it and mention us again

@isaacdorfman isaacdorfman force-pushed the increase-unit-test-coverage branch from 0a8678d to c27b2dd Compare January 15, 2023 12:11
@@ -39,6 +47,98 @@ type ClusterResource struct {
collection *cmv1.ClustersClient
}

type ClusterClient interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new interface and its implementation should be located in another package/file
@bardielle what do you think

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirarg agree with you.
I think it's important in order to reuse it later in cluster rosa classic resource

Copy link
Collaborator

@bardielle bardielle Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isaacdorfman this interface must be align with the upcoming changes in cluster_rosa_classic resource
so if need to add more interface's methods please add them and later implements that with return or whatever is needed in the simple cluster resource
In that way you'll have 3 files

  • interface
  • implementation for cluster resource
  • implementation for cluster rosa classic resource
  • cluster resource (?)

@@ -36,10 +36,17 @@ ldflags:=\
-X $(import_path)/build.Commit=$(commit) \
$(NULL)

.PHONY: gen-mocks
gen-mocks:
mockgen -source=provider/cluster_resource.go -destination=provider/cluster_resource_mock.go -package provider
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding specific files here in the Makefile, add go:generate mockgen comment near the interface to be mocked and use go:genernate command recursively in the project directory

Comment on lines 132 to 32
type ClusterResourceUtils interface {
populateClusterState(object *cmv1.Cluster, state *ClusterState)
createClusterObject(ctx context.Context,
state *ClusterState, diags diag.Diagnostics) (*cmv1.Cluster, error)
}

type ClusterResourceUtilsImpl struct {
clusterClient ClusterClient
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this new Interface and its implementation should be moved to different package/File

Comment on lines +541 to +433
clusterClient := &ClusterClientImpl{InternalClient: r.collection}
clusterUtils := ClusterResourceUtilsImpl{clusterClient: clusterClient}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be created only once when calling to ClusterResource constructor and not in each function


It("Creates ClusterBuilder with correct field values", func() {
generateBaseClusterMap := func() map[string]interface{} {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move all those functions out from the describe
You can use "var" scope

@@ -175,4 +239,248 @@ var _ = Describe("Cluster creation", func() {
Expect(clusterState.AWSSecretAccessKey.Value).To(Equal(awsSecretAccessKey))
Expect(clusterState.AWSPrivateLink.Value).To(Equal(privateLink))
})

Describe("clusterUtils::create", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The describes doesn't describe what you would like to test in that scope

})
})

Describe("clusterUtils::update", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


Describe("clusterUtils::update", func() {
It("invokes cluster update on the client", func() {
ctrl := generateGinkgoController()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the section Beforeach()

{
			ctrl := generateGinkgoController()
			clusterCurrentState := generateBaseClusterState()
			clusterDesiredState := generateBaseClusterState()
			clusterDesiredState.ComputeNodes.Value = clusterDesiredState.ComputeNodes.Value + 1
			clusterMap := generateBaseClusterMap()
			clusterMap["nodes"].(map[string]interface{})["compute"] = clusterDesiredState.ComputeNodes.Value
}

})
})

Describe("clusterUtils::delete", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@isaacdorfman isaacdorfman force-pushed the increase-unit-test-coverage branch from c27b2dd to 36a5775 Compare January 17, 2023 15:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants