Skip to content

Commit

Permalink
bonsai
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Oct 8, 2023
1 parent 1fe9a0b commit 9ceae76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 11 additions & 3 deletions cmd/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ var coverageCmd = &cobra.Command{
return err
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Spec", "Coverage"})
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(false)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold}, tablewriter.Colors{tablewriter.Bold})
table.SetColumnAlignment([]int{tablewriter.ALIGN_LEFT, tablewriter.ALIGN_RIGHT})
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetHeaderLine(false)
table.SetNoWhiteSpace(true)
table.SetRowSeparator("-")
table.SetHeaderLine(true)
table.SetBorder(false)
for _, spec := range cov.Specs {
var total, covered int
Expand All @@ -84,7 +88,10 @@ var coverageCmd = &cobra.Command{
}
}
persent := float64(covered) / float64(total) * 100
table.Append([]string{spec.Key + " ", fmt.Sprintf("%.1f%%", persent)})
table.Append([]string{spec.Key, fmt.Sprintf("%.1f%%", persent)})
}
if flgs.Debug {
cmd.Println()
}
table.Render()
return nil
Expand All @@ -93,6 +100,7 @@ var coverageCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(coverageCmd)
coverageCmd.Flags().BoolVarP(&flgs.Debug, "debug", "", false, flgs.Usage("Debug"))
coverageCmd.Flags().StringSliceVarP(&flgs.Vars, "var", "", []string{}, flgs.Usage("Vars"))
coverageCmd.Flags().StringSliceVarP(&flgs.Runners, "runner", "", []string{}, flgs.Usage("Runners"))
coverageCmd.Flags().StringSliceVarP(&flgs.Overlays, "overlay", "", []string{}, flgs.Usage("Overlays"))
Expand Down
11 changes: 6 additions & 5 deletions coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type specCoverage struct {
func (o *operator) collectCoverage(ctx context.Context) (*coverage, error) {
cov := &coverage{}
// Collect coverage for openapi3
for _, r := range o.httpRunners {
for name, r := range o.httpRunners {
ov, ok := r.validator.(*openApi3Validator)
if !ok {
o.Debugf("%s does not have openapi3 spec document (%s)\n", name, o.bookPath)
continue
}
key := fmt.Sprintf("%s:%s", ov.doc.Info.Title, ov.doc.Info.Version)
Expand Down Expand Up @@ -78,7 +79,7 @@ func (o *operator) collectCoverage(ctx context.Context) (*coverage, error) {
}
route, _, err := router.FindRoute(req)
if err != nil {
o.Warnf("%s %s was not matched in %s\n", method, p, key)
o.Debugf("%s %s was not matched in %s (%s)\n", method, p, key, o.bookPath)
continue
}
mkey := fmt.Sprintf("%s %s", method, route.Path)
Expand All @@ -96,7 +97,7 @@ func (o *operator) collectCoverage(ctx context.Context) (*coverage, error) {
break L
}
}
o.Warnf("%s %s was not matched in %s\n", method, p, key)
o.Debugf("%s %s was not matched in %s (%s)\n", method, p, key, o.bookPath)
}
}
}
Expand All @@ -105,7 +106,7 @@ func (o *operator) collectCoverage(ctx context.Context) (*coverage, error) {
// Collect coverage for protocol buffers
for name, r := range o.grpcRunners {
if err := r.resolveAllMethodsUsingProtos(ctx); err != nil {
o.Warnf("%s was not resolved: %s\n", name, err)
o.Debugf("%s was not resolved: %s (%s)\n", name, err, o.bookPath)
continue
}
for k := range r.mds {
Expand Down Expand Up @@ -136,7 +137,7 @@ func (o *operator) collectCoverage(ctx context.Context) (*coverage, error) {
return scov.Key == service
})
if !ok {
o.Warnf("%s/%s was not matched\n", service, method)
o.Debugf("%s/%s was not matched (%s)\n", service, method, o.bookPath)
continue
}
scov.Coverages[method]++
Expand Down

0 comments on commit 9ceae76

Please sign in to comment.