Skip to content

Commit

Permalink
UT for detect default method
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubramanianaks committed Jun 8, 2023
1 parent dd918aa commit 86dedad
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,45 @@ func getAllDeploymentFiles(src string) (error, []string) {
})
return err, deploymentFiles
}

func TestDetectDefaults(t *testing.T) {
ioutil.WriteFile("build.gradle", []byte("sourceCompatibility = '11'\ntargetCompatibility = '12'"), 0644)
mockCC := &createCmd{}
mockDraftConfig := &config.DraftConfig{}
mockCC.detectDefaults(mockDraftConfig, "gradlew")
assert.Equal(t, 2, len(mockDraftConfig.DetectedDefaults))
assert.Equal(t, "VERSION", mockDraftConfig.DetectedDefaults[0].Name)
assert.Equal(t, "11-jre", mockDraftConfig.DetectedDefaults[0].Value)
assert.Equal(t, "BUILDERVERSION", mockDraftConfig.DetectedDefaults[1].Name)
assert.Equal(t, "jdk12", mockDraftConfig.DetectedDefaults[1].Value)
os.Remove("build.gradle")
}

func TestDetectDefaultsNoGradle(t *testing.T) {
mockCC := &createCmd{}
mockDraftConfig := &config.DraftConfig{}
mockCC.detectDefaults(mockDraftConfig, "maven")
assert.Equal(t, 0, len(mockDraftConfig.DetectedDefaults))
}

func TestDetectDefaultsNoSourceComptability(t *testing.T) {
ioutil.WriteFile("build.gradle", []byte("targetCompatibility = '12'"), 0644)
mockCC := &createCmd{}
mockDraftConfig := &config.DraftConfig{}
mockCC.detectDefaults(mockDraftConfig, "gradlew")
assert.Equal(t, 1, len(mockDraftConfig.DetectedDefaults))
assert.Equal(t, "BUILDERVERSION", mockDraftConfig.DetectedDefaults[0].Name)
assert.Equal(t, "jdk12", mockDraftConfig.DetectedDefaults[0].Value)
os.Remove("build.gradle")
}

func TestDetectDefaultsNoTargetComptability(t *testing.T) {
ioutil.WriteFile("build.gradle", []byte("sourceCompatibility = '11'"), 0644)
mockCC := &createCmd{}
mockDraftConfig := &config.DraftConfig{}
mockCC.detectDefaults(mockDraftConfig, "gradlew")
assert.Equal(t, 1, len(mockDraftConfig.DetectedDefaults))
assert.Equal(t, "VERSION", mockDraftConfig.DetectedDefaults[0].Name)
assert.Equal(t, "11-jre", mockDraftConfig.DetectedDefaults[0].Value)
os.Remove("build.gradle")
}

0 comments on commit 86dedad

Please sign in to comment.