Skip to content

Commit

Permalink
Merge pull request #50 from k1LoW/fix-create_table
Browse files Browse the repository at this point in the history
Fix --create-bq-table
  • Loading branch information
k1LoW authored Aug 24, 2021
2 parents 0f3920b + 1f47520 commit a71e6cb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func createBQTable(ctx context.Context, c *config.Config) error {
if !c.DatastoreConfigReady() {
return errors.New("datastore config not ready")
if !c.ReportConfigDatastoresReady() {
return errors.New("report.datastores is not set")
}
if err := c.BuildReportConfig(); err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions config/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (c *Config) ReportConfigReady() bool {
if c.Report == nil {
return false
}
if !c.ReportConfigDatastoresReady() {
_, _ = fmt.Fprintf(os.Stderr, "Skip storing the report: report.datastores is not set %v\n", c.Report.Datastores)
return false
}
ok, err := CheckIf(c.Report.If)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Skip storing the report: %v\n", err)
Expand All @@ -27,6 +31,13 @@ func (c *Config) ReportConfigReady() bool {
return true
}

func (c *Config) ReportConfigDatastoresReady() bool {
if c.Report == nil {
return false
}
return len(c.Report.Datastores) > 0
}

func (c *Config) BuildReportConfig() error {
if len(c.Report.Datastores) == 0 {
return errors.New("report.datastores is not set")
Expand Down
33 changes: 33 additions & 0 deletions config/report_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package config

import (
"testing"
)

func TestReportConfigReady(t *testing.T) {
tests := []struct {
c *Config
want bool
}{
{
New(),
false,
},
{
&Config{
Report: &ConfigReport{
Datastores: []string{
"s3://octocov-test/reports",
},
},
},
true,
},
}
for _, tt := range tests {
got := tt.c.ReportConfigReady()
if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
}
}
}

0 comments on commit a71e6cb

Please sign in to comment.