Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
shihyuho committed Jan 20, 2024
1 parent b05b31e commit 47f10ce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions calc/java_tool_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

const (
EnvJavaToolOptions = "JAVA_TOOL_OPTIONS"
separator = " "
OptionsSeparator = " "
)

// ContributeOptions 固定要貢獻 jvm 的參數, 這些參數可能是 libjvm 在 build image 時加的而非計算出來的, 或是我們自己想要加上去的都可以放
Expand All @@ -26,7 +26,7 @@ func BuildJavaToolOptions() *JavaToolOptions {
if o == "" {
o = option
} else {
o += separator + option
o += OptionsSeparator + option
}
}
}
Expand Down
66 changes: 35 additions & 31 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
package main

import (
"github.com/softleader/memory-calculator/calc"
"strings"
"testing"
"github.com/softleader/memory-calculator/calc"
"strings"
"testing"
)

func TestMemoryCalculation_WithLoadedClassCount(t *testing.T) {
calculator := calc.NewCalculator()
*calculator.LoadedClassCount = 1000
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")
}
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, "")
}
options = strings.ReplaceAll(options, calc.OptionsSeparator, "")

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%"
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, "")
}
options = strings.ReplaceAll(options, calc.OptionsSeparator, "")

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")
}
if options == "" {
t.Errorf("Execute returned an empty string")
}
}

0 comments on commit 47f10ce

Please sign in to comment.