Skip to content

Commit

Permalink
test: pass coverage threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Dec 4, 2024
1 parent 6ac6c3e commit a131759
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ var (

func check(err interface{}) {
if err != nil {
log.Fatal(err)
panic(err)
}
}
Expand Down
26 changes: 26 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"github.com/spf13/viper"
"os"
"testing"
Expand All @@ -23,6 +24,22 @@ func Test_ExecuteRootCommand(t *testing.T) {
t.Fatal(err)
}

t.Run("Invalid algod-endpoint", func(t *testing.T) {
viper.Set("algod-endpoint", "")
err := rootCmd.Execute()
if err == nil {
t.Error("No error for invalid algod-endpoint")
}
clearViper()
})
t.Run("Invalid algod-token", func(t *testing.T) {
viper.Set("algod-endpoint", "http://localhost:8080")
viper.Set("algod-token", "")
err := rootCmd.Execute()
if err == nil {
t.Error("No error for invalid algod-endpoint")
}
})
t.Run("InitConfig", func(t *testing.T) {
cwd, _ := os.Getwd()
viper.Set("algod-token", "")
Expand Down Expand Up @@ -90,4 +107,13 @@ func Test_ExecuteRootCommand(t *testing.T) {
}
clearViper()
})

t.Run("check error", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
check(errors.New("test"))
})
}

0 comments on commit a131759

Please sign in to comment.