Skip to content

Commit

Permalink
reformat + fix check updates
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanasati committed Dec 31, 2023
1 parent 4b803ba commit f5826bb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
5 changes: 3 additions & 2 deletions internal/check_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type releaseInfo struct {
}

func (ri releaseInfo) display() {
fmt.Printf("\nnote: new `%s` of iris is now available at `%s` \n\nfull release article: \n%s \n%s\n", ri.TagName, ri.HTMLURL, ri.Name, ri.Body)
fmt.Printf("\nnote: new `%s` of bench is now available at `%s` \n\nfull release article: \n%s \n%s\n", ri.TagName, ri.HTMLURL, ri.Name, ri.Body)
}

func CheckForUpdates(currentVersion string) {
Expand All @@ -84,7 +84,7 @@ func CheckForUpdates(currentVersion string) {
return
}

url := "https://api.github.com/repos/Shravan-1908/iris/releases/latest"
url := "https://api.github.com/repos/Shravan-1908/bench/releases/latest"
releaseInfo := releaseInfo{}
resp, err := http.Get(url)
if err != nil {
Expand All @@ -96,6 +96,7 @@ func CheckForUpdates(currentVersion string) {
}
json.Unmarshal(data, &releaseInfo)
writeLastCheckedTime(now)

if compareSemverStrings(releaseInfo.TagName, currentVersion) != greater {
// no new version
return
Expand Down
12 changes: 11 additions & 1 deletion internal/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ func (result *Result) Export(exportFormats string) {
Log("red", "Failed to export the results to json.")
return
}
writeToFile(string(jsonText), "bench-summary.json")
e = writeToFile(string(jsonText), "bench-summary.json")
if e == nil {
absPath, err := filepath.Abs("bench-summary.json")
if err != nil {
Log("red", "unable to get the absolute path for json file: "+err.Error())
} else {
Log("green", "Successfully wrote benchmark summary to `"+absPath+"`.")
}
} else {
Log("red", "Unable to write to file ./bench-summary.json: "+e.Error())
}

} else if exportFormat == "csv" {
csvify(result)
Expand Down
12 changes: 2 additions & 10 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,13 @@ func getBenchDir() string {
panic(e)
}

// * determining iris's directory
dir := filepath.Join(usr.HomeDir, ".iris")
// * determining bench's directory
dir := filepath.Join(usr.HomeDir, ".bench")

if !checkPathExists(dir) {
os.Mkdir(dir, os.ModePerm)
}

subDirs := []string{"wallpapers", "temp", "cache"}
for _, subDir := range subDirs {
dirPath := filepath.Join(dir, subDir)
if !checkPathExists(dirPath) {
os.Mkdir(dirPath, os.ModePerm)
}
}

return dir
}

Expand Down
16 changes: 8 additions & 8 deletions internal/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package internal

import (
"testing"
"os"
"testing"
)

func Test_format(t *testing.T) {
Expand All @@ -17,20 +17,20 @@ func Test_format(t *testing.T) {
want string
}{
{
name: "empty test",
args: args{"", map[string]string{}},
name: "empty test",
args: args{"", map[string]string{}},
want: "",
},

{
name: "name test",
args: args{"hello this is me, ${name}", map[string]string{"name": "Shravan"}},
name: "name test",
args: args{"hello this is me, ${name}", map[string]string{"name": "Shravan"}},
want: "hello this is me, Shravan",
},

{
name: "long sentence test",
args: args{"${go} offers cool concurrency features like ${c1} and ${c2}. and it's ${adj}!", map[string]string{"go": "Golang", "c1": "goroutines", "c2": "channels", "adj": "amazing"}},
name: "long sentence test",
args: args{"${go} offers cool concurrency features like ${c1} and ${c2}. and it's ${adj}!", map[string]string{"go": "Golang", "c1": "goroutines", "c2": "channels", "adj": "amazing"}},
want: "Golang offers cool concurrency features like goroutines and channels. and it's amazing!",
},
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func Test_writeToFile(t *testing.T) {
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := writeToFile(tt.args.text, tt.args.filename); (err != nil) != tt.wantErr {
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
// NAME is the executable name.
NAME = "bench"
// VERSION is the executable version.
VERSION = "v0.4.0"
VERSION = "v0.2.0"
)

// NO_COLOR is a global variable that is used to determine whether or not to enable color output.
Expand Down Expand Up @@ -91,7 +91,7 @@ func main() {

command, err := shlex.Split(args["command"].Value)
if err != nil {
internal.Log("red", "unable to parse the given command: " + args["command"].Value)
internal.Log("red", "unable to parse the given command: "+args["command"].Value)
internal.Log("white", err.Error())
return
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func main() {
// warmup runs
for i := 0; i < warmupRuns; i++ {
// todo replace running logs with a progress bar in non-verbose mode
internal.Log("purple", fmt.Sprintf("***********\nRunning warmup %d\n***********", i + 1))
internal.Log("purple", fmt.Sprintf("***********\nRunning warmup %d\n***********", i+1))
_, e := run(command, verbose, ignoreError)
if e != nil {
return
Expand Down Expand Up @@ -164,11 +164,11 @@ func main() {
panic("unable to parse duration from string: " + stddevString + "\n" + err.Error())
}
result := internal.Result{
Started: started,
Ended: ended,
Command: strings.Join(command, " "),
Iterations: iterations,
Average: avgDuration.String(),
Started: started,
Ended: ended,
Command: strings.Join(command, " "),
Iterations: iterations,
Average: avgDuration.String(),
StandardDeviation: stddevDuration.String(),
}

Expand Down

0 comments on commit f5826bb

Please sign in to comment.