Skip to content

Commit

Permalink
fix: 🐛 static code error and mock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskaransarkaria committed Sep 24, 2024
1 parent 276c875 commit dae88f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pkg/environment/isRdsVersionMismatched.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func IsRdsVersionMismatched(outputTerraform string) (*RdsVersionResults, error)
match, _ := regexp.MatchString("Error: updating RDS DB Instance .* api error InvalidParameterCombination:.* from .* to .*", outputTerraform)

if !match {
return nil, errors.New("terraform is failing but it doesn't look like a rds version mismatch.")
return nil, errors.New("terraform is failing but it doesn't look like a rds version mismatch")
}

versionRe := regexp.MustCompile(`from (?P<actual_db_version>\d+\.\d+) to (?P<terraform_db_version>\d+\.\d+)`)
Expand All @@ -32,11 +32,11 @@ func IsRdsVersionMismatched(outputTerraform string) (*RdsVersionResults, error)
sanitisedNames := removeInputStr(moduleMatches)

if !checkVersionDowngrade(sanitisedVersions) {
return nil, errors.New("terraform is failing, but it isn't trying to downgrade the RDS versions so it needs more investigation.")
return nil, errors.New("terraform is failing, but it isn't trying to downgrade the RDS versions so it needs more investigation")
}

if len(sanitisedVersions) != len(sanitisedNames) {
return nil, fmt.Errorf("Error: there is an inconistent number of versions vs module names, there should be an even amount but we have %d sets of versions and %d module names", len(sanitisedVersions), len(sanitisedNames))
return nil, fmt.Errorf("error: there is an inconistent number of versions vs module names, there should be an even amount but we have %d sets of versions and %d module names", len(sanitisedVersions), len(sanitisedNames))
}

return &RdsVersionResults{
Expand All @@ -57,12 +57,12 @@ func checkVersionDowngrade(versions [][]string) bool {
adjustedAcc := strings.Join(splitAcc, "")
adjustedTf := strings.Join(splitTf, "")

acc, err := strconv.ParseInt(adjustedAcc, 0, 64)
tf, err := strconv.ParseInt(adjustedTf, 0, 64)
acc, accErr := strconv.ParseInt(adjustedAcc, 0, 64)
tf, tfErr := strconv.ParseInt(adjustedTf, 0, 64)

isUpgrade := tf > acc

if err != nil || isUpgrade {
if accErr != nil || tfErr != nil || isUpgrade {
isValid = false
break
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (m *mockGithub) IsMerged(ctx context.Context, owner string, repo string, nu
return true, nil, nil
}

func (m *mockGithub) Create(ctx context.Context, owner string, repo string, pr *github.NewPullRequest) (*github.PullRequest, *github.Response, error) {
return nil, nil, nil
}

func TestNewGithubClient(t *testing.T) {
type args struct {
config *GithubClientConfig
Expand Down Expand Up @@ -51,7 +55,6 @@ func TestNewGithubClient(t *testing.T) {
}

func TestGithubClient_GetChangedFiles(t *testing.T) {

mc := &mockGithub{
resp: []*github.CommitFile{
{
Expand Down Expand Up @@ -95,13 +98,11 @@ func TestGithubClient_IsMerged(t *testing.T) {
PullRequests: mc,
}
got, err := gh.IsMerged(8344)

if err != nil {
t.Errorf("GithubClient.IsMerged() error = %v, wantErr %v", err, nil)
return
}
if got != mc.merged {
t.Errorf("GithubClient.IsMerged() = %v, want %v", got, true)
}

}

0 comments on commit dae88f5

Please sign in to comment.