-
Notifications
You must be signed in to change notification settings - Fork 20
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
3 changed files
with
148 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package leeway | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestParseGoCoverOutput(t *testing.T) { | ||
type Expectation struct { | ||
Error string | ||
Coverage int | ||
FuncsWithoutTest int | ||
FuncsWithTest int | ||
} | ||
tests := []struct { | ||
Name string | ||
Input string | ||
Expectation Expectation | ||
}{ | ||
{ | ||
Name: "empty", | ||
}, | ||
{ | ||
Name: "valid", | ||
Input: `github.com/gitpod-io/leeway/store.go:165: Get 100.0% | ||
github.com/gitpod-io/leeway/store.go:173: Set 100.0% | ||
github.com/gitpod-io/leeway/store.go:178: Delete 100.0% | ||
github.com/gitpod-io/leeway/store.go:183: Scan 80.0% | ||
github.com/gitpod-io/leeway/store.go:194: Close 0.0% | ||
github.com/gitpod-io/leeway/store.go:206: Upsert 0.0%`, | ||
Expectation: Expectation{ | ||
Coverage: 63, | ||
FuncsWithoutTest: 2, | ||
FuncsWithTest: 4, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
var act Expectation | ||
|
||
var err error | ||
act.Coverage, act.FuncsWithoutTest, act.FuncsWithTest, err = parseGoCoverOutput(test.Input) | ||
if err != nil { | ||
act.Error = err.Error() | ||
} | ||
|
||
if diff := cmp.Diff(test.Expectation, act); diff != "" { | ||
t.Errorf("parseGoCoverOutput() mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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