-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,82 @@ | ||
package calc | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"testing" | ||
) | ||
|
||
type MockContributor struct { | ||
Called bool | ||
Called bool | ||
} | ||
|
||
func (m *MockContributor) Contribute() error { | ||
m.Called = true | ||
return nil | ||
m.Called = true | ||
return nil | ||
} | ||
|
||
func TestCalculator_Contribute(t *testing.T) { | ||
mockContributor := &MockContributor{} | ||
mockContributor := &MockContributor{} | ||
|
||
err := contribute(mockContributor) | ||
if err != nil { | ||
t.Fatalf("contribute returned an error: %v", err) | ||
} | ||
err := contribute(mockContributor) | ||
if err != nil { | ||
t.Fatalf("contribute returned an error: %v", err) | ||
} | ||
|
||
if !mockContributor.Called { | ||
t.Errorf("Contributor's Contribute method was not called") | ||
} | ||
if !mockContributor.Called { | ||
t.Errorf("Contributor's Contribute method was not called") | ||
} | ||
} | ||
|
||
func TestCalculator_buildHelpers_HasCaCerts(t *testing.T) { | ||
calculator := NewCalculator() | ||
calculator.JVMCacerts.Set("some-value") | ||
calculator := NewCalculator() | ||
calculator.JVMCacerts.Set("some-value") | ||
|
||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
|
||
if _, ok := helpers[helperOpensslCertificateLoader]; !ok { | ||
t.Errorf(helperOpensslCertificateLoader + " helper not found in helpers") | ||
} | ||
if _, ok := helpers[helperOpensslCertificateLoader]; !ok { | ||
t.Errorf(helperOpensslCertificateLoader + " helper not found in helpers") | ||
} | ||
} | ||
|
||
func TestCalculator_buildHelpers_NoCaCerts(t *testing.T) { | ||
calculator := NewCalculator() | ||
calculator := NewCalculator() | ||
|
||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
|
||
if _, ok := helpers[helperOpensslCertificateLoader]; ok { | ||
t.Errorf(helperOpensslCertificateLoader + " helper should not be present") | ||
} | ||
if _, ok := helpers[helperOpensslCertificateLoader]; ok { | ||
t.Errorf(helperOpensslCertificateLoader + " helper should not be present") | ||
} | ||
} | ||
|
||
func TestCalculator_buildHelpers_EnableNmt(t *testing.T) { | ||
calculator := NewCalculator() | ||
*calculator.EnableNmt = true | ||
calculator := NewCalculator() | ||
*calculator.EnableNmt = true | ||
|
||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
|
||
if _, ok := helpers[helperNmt]; !ok { | ||
t.Errorf(helperNmt + " helper should be present") | ||
} | ||
if _, ok := helpers[helperNmt]; !ok { | ||
t.Errorf(helperNmt + " helper should be present") | ||
} | ||
} | ||
|
||
func TestCalculator_buildHelpers_DisableNmt(t *testing.T) { | ||
calculator := NewCalculator() | ||
*calculator.EnableNmt = false | ||
calculator := NewCalculator() | ||
*calculator.EnableNmt = false | ||
|
||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
helpers, err := calculator.buildHelpers() | ||
if err != nil { | ||
t.Fatalf("buildHelpers returned an error: %v", err) | ||
} | ||
|
||
if _, ok := helpers[helperNmt]; ok { | ||
t.Errorf(helperNmt + " helper should not be present") | ||
} | ||
} | ||
|
||
func TestCalculator_Execute_Success(t *testing.T) { | ||
calculator := NewCalculator() | ||
*calculator.LoadedClassCount = 1000 | ||
|
||
jto, err := calculator.Execute() | ||
if err != nil { | ||
t.Fatalf("Execute returned an error: %v", err) | ||
} | ||
options := jto.String() | ||
for _, o := range contributeOptions { | ||
options = strings.ReplaceAll(options, o, "") | ||
} | ||
if options == "" { | ||
t.Errorf("Execute returned an empty string") | ||
} | ||
if _, ok := helpers[helperNmt]; ok { | ||
t.Errorf(helperNmt + " helper should not be present") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/softleader/memory-calculator/calc" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestMemoryCalculation_WithLoadedClassCount(t *testing.T) { | ||
calculator := calc.NewCalculator() | ||
*calculator.LoadedClassCount = 1000 | ||
|
||
jto, err := calculator.Execute() | ||
if err != nil { | ||
t.Fatalf("Execute returned an error: %v", err) | ||
} | ||
options := jto.String() | ||
for _, o := range calc.ContributeOptions { | ||
options = strings.ReplaceAll(options, o, "") | ||
} | ||
if options == " " { | ||
t.Errorf("Execute returned an empty string") | ||
} | ||
} | ||
|
||
func TestMemoryCalculation_WithoutLoadedClassCount(t *testing.T) { | ||
calculator := calc.NewCalculator() | ||
*calculator.AppPath = "." | ||
*calculator.JVMClassCount = 1000 | ||
*calculator.JVMClassAdj = "150%" | ||
|
||
jto, err := calculator.Execute() | ||
if err != nil { | ||
t.Fatalf("Execute returned an error: %v", err) | ||
} | ||
options := jto.String() | ||
for _, o := range calc.ContributeOptions { | ||
options = strings.ReplaceAll(options, o, "") | ||
} | ||
if options == " " { | ||
t.Errorf("Execute returned an empty string") | ||
} | ||
} |