Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coverage #63

Merged
merged 10 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions commands/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c TestCommand) Execute() int {

coverageReport, err := tf.NewCoverageReportFromState(state)
if err != nil {
log.Fatalf("[ERROR] error produce coverage report: %+v", err)
log.Printf("[ERROR] error produce coverage report: %+v", err)
}
log.Printf("[INFO] the coverage report has been produced.")
storePassReport(passReport, coverageReport, reportDir, allPassedReportFileName)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (c TestCommand) Execute() int {
passReport := tf.NewPassReport(plan)
coverageReport, err := tf.NewCoverageReport(plan)
if err != nil {
log.Fatalf("[ERROR] error produce coverage report: %+v", err)
log.Printf("[ERROR] error produce coverage report: %+v", err)
}
storePassReport(passReport, coverageReport, reportDir, partialPassedReportFileName)

Expand Down
60 changes: 42 additions & 18 deletions coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ type Model struct {
IsReadOnly bool `json:"IsReadOnly,omitempty"`
IsRequired bool `json:"IsRequired,omitempty"`
Item *Model `json:"Item,omitempty"`
ModelName string `json:"ModelName,omitempty"`
Properties *map[string]*Model `json:"Properties,omitempty"`
SourceFile string `json:"SourceFile,omitempty"`
TotalCount int `json:"TotalCount,omitempty"`
Type *string `json:"Type,omitempty"`
Variants *map[string]*Model `json:"Variants,omitempty"`
VariantType *string `json:"VariantType,omitempty"`
}

func (m *Model) MarkCovered(root interface{}) {
Expand Down Expand Up @@ -66,39 +68,58 @@ func (m *Model) MarkCovered(root interface{}) {
}

case map[string]interface{}:
if m.Discriminator != nil {
isMatchProperty := true
if m.Discriminator != nil && m.Variants != nil {
Loop:
for k, v := range value {
if k == *m.Discriminator {
if m.Variants == nil {
log.Printf("[ERROR] unexpected discriminator %s in %s\n", k, m.Identifier)
if m.ModelName == v.(string) {
break
}
if _, ok := (*m.Variants)[v.(string)]; !ok {
log.Printf("[ERROR] unexpected variant %s in %s\n", v.(string), m.Identifier)
if m.VariantType != nil && *m.VariantType == v.(string) {
break
}
(*m.Variants)[v.(string)].MarkCovered(value)
break
if variant, ok := (*m.Variants)[v.(string)]; ok {
isMatchProperty = false
variant.MarkCovered(value)

break
}
for _, variant := range *m.Variants {
if variant.VariantType != nil && *variant.VariantType == v.(string) {
isMatchProperty = false
variant.MarkCovered(value)

break Loop
}
}
log.Printf("[ERROR] unexpected variant %s in %s\n", v.(string), m.Identifier)
}
}
}
for k, v := range value {
if m.Properties == nil {
if !m.HasAdditionalProperties && m.Discriminator == nil {
log.Printf("[WARN] unexpected key %s in %s\n", k, m.Identifier)

if isMatchProperty {
for k, v := range value {
if m.Properties == nil {
if !m.HasAdditionalProperties {
log.Printf("[WARN] unexpected key %s in %s\n", k, m.Identifier)
}
return
}
return
}
if _, ok := (*m.Properties)[k]; !ok {
if !m.HasAdditionalProperties && m.Discriminator == nil {
log.Printf("[WARN] unexpected key %s in %s\n", k, m.Identifier)
if _, ok := (*m.Properties)[k]; !ok {
if !m.HasAdditionalProperties {
log.Printf("[WARN] unexpected key %s in %s\n", k, m.Identifier)
return
}
}
(*m.Properties)[k].MarkCovered(v)
}
(*m.Properties)[k].MarkCovered(v)
}

case nil:

default:
log.Fatalf("[ERROR] unexpect type %T for json unmarshaled value", value)
log.Printf("[ERROR] unexpect type %T for json unmarshaled value", value)
}
}

Expand Down Expand Up @@ -137,6 +158,9 @@ func (m *Model) CountCoverage() (int, int) {

if m.Properties != nil {
for _, v := range *m.Properties {
if v.IsReadOnly {
continue
}
covered, total := v.CountCoverage()
m.CoveredCount += covered
m.TotalCount += total
Expand Down
Loading
Loading