Skip to content

Commit

Permalink
lint: Fix errcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Jul 13, 2024
1 parent cd01573 commit eaaf327
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion adapter/mysql/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.db.MustExec("DROP TABLE IF EXISTS followers;")
adapter.db.MustExec("DROP TABLE IF EXISTS articles;")
Expand Down
2 changes: 1 addition & 1 deletion adapter/oracle/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

// adapter.db.MustExec("DROP TABLE followers")
// adapter.db.MustExec("DROP TABLE articles")
Expand Down
2 changes: 1 addition & 1 deletion adapter/postgresql/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.db.MustExec("DROP TABLE IF EXISTS followers;")
adapter.db.MustExec("DROP TABLE IF EXISTS articles;")
Expand Down
2 changes: 1 addition & 1 deletion adapter/sqlite3/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.DB.MustExec("PRAGMA foreign_keys = ON;")

Expand Down
4 changes: 2 additions & 2 deletions cmd/plant_erd-oracle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func main() {
return errors.WithStack(err)
}

defer close()
defer close() //nolint:errcheck

schema, err := lib.LoadSchema(adapter)
if err != nil {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
}

sort.Sort(cli.CommandsByName(app.Commands))
Expand Down
12 changes: 6 additions & 6 deletions cmd/plant_erd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func main() {
return errors.WithStack(err)
}

defer close()
defer close() //nolint:errcheck

schema, err := lib.LoadSchema(adapter)
if err != nil {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
},
},
{
Expand Down Expand Up @@ -128,14 +128,14 @@ func main() {
return errors.WithStack(err)
}

defer close()
defer close() //nolint:errcheck

schema, err := lib.LoadSchema(adapter)
if err != nil {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
},
},
{
Expand Down Expand Up @@ -192,14 +192,14 @@ func main() {
return errors.WithStack(err)
}

defer close()
defer close() //nolint:errcheck

schema, err := lib.LoadSchema(adapter)
if err != nil {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
},
},
}
Expand Down
46 changes: 36 additions & 10 deletions lib/erd_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lib

import (
"bytes"
"github.com/stretchr/testify/require"
"io"
"os"
"path/filepath"
Expand All @@ -19,7 +20,7 @@ func withDatabase(callback func(*sqlite3.Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.DB.MustExec("PRAGMA foreign_keys = ON;")

Expand Down Expand Up @@ -214,7 +215,8 @@ func TestErdGenerator_output_ToFile(t *testing.T) {
Filepath: filePath,
}

g.output("aaa")
err := g.output("aaa")
require.NoError(t, err)

data, err := os.ReadFile(filePath)

Expand All @@ -237,10 +239,16 @@ func captureStdout(f func()) string {
f()

os.Stdout = stdout
w.Close()
err = w.Close()
if err != nil {
panic(err)
}

var buf bytes.Buffer
io.Copy(&buf, r)
_, err = io.Copy(&buf, r)
if err != nil {
panic(err)
}

return buf.String()
}
Expand Down Expand Up @@ -512,7 +520,10 @@ func ExampleErdGenerator_Run_two_tables_with_PlantUML() {
}

generator := ErdGenerator{Format: "plant_uml"}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// entity articles {
Expand Down Expand Up @@ -543,7 +554,10 @@ func ExampleErdGenerator_Run_many_tables_with_PlantUML() {
}

generator := ErdGenerator{Format: "plant_uml"}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// entity articles {
Expand Down Expand Up @@ -634,7 +648,10 @@ func ExampleErdGenerator_Run_many_tables_within_a_distance_of_1_from_the_article
}

generator := ErdGenerator{Format: "plant_uml", Table: "articles", Distance: 1}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// entity articles {
Expand Down Expand Up @@ -709,7 +726,10 @@ func ExampleErdGenerator_Run_two_tables_with_Mermaid() {
}

generator := ErdGenerator{Format: "mermaid"}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// erDiagram
Expand Down Expand Up @@ -738,7 +758,10 @@ func ExampleErdGenerator_Run_many_tables_with_Mermaid() {
}

generator := ErdGenerator{Format: "mermaid"}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// erDiagram
Expand Down Expand Up @@ -810,7 +833,10 @@ func ExampleErdGenerator_Run_many_tables_within_a_distance_of_1_from_the_article
}

generator := ErdGenerator{Format: "mermaid", Table: "articles", Distance: 1}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// erDiagram
Expand Down

0 comments on commit eaaf327

Please sign in to comment.