Skip to content

Commit

Permalink
Run gofmt against project
Browse files Browse the repository at this point in the history
  • Loading branch information
mpchadwick committed Nov 15, 2020
1 parent a3160a0 commit 487421a
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 42 deletions.
5 changes: 2 additions & 3 deletions integration/dbanon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var version string
func TestDbanon(t *testing.T) {
os.Chdir("..")
dir, _ := os.Getwd()

cmd1 := exec.Command(path.Join(dir, binaryName))
out1, _ := cmd1.CombinedOutput()
res1 := strings.TrimSpace(string(out1))
Expand All @@ -34,7 +34,6 @@ func TestDbanon(t *testing.T) {
t.Errorf("Got %s expected %s", res2, versRes)
}


cmdStr3 := "cat integration/magento_raw.sql | ./dbanon -config=magento2"
cmd3 := exec.Command("bash", "-c", cmdStr3)
out3, _ := cmd3.CombinedOutput()
Expand Down Expand Up @@ -68,4 +67,4 @@ func TestDbanon(t *testing.T) {
if strings.Contains(res5, "Bob Smith") {
t.Error("Expected no Bob Smith")
}
}
}
10 changes: 4 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"flag"
"fmt"
"github.com/blang/semver"
"github.com/sirupsen/logrus"
"github.com/mpchadwick/dbanon/src"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"github.com/sirupsen/logrus"
"io/ioutil"
"log"
"runtime/pprof"
"os"
"runtime/pprof"
)

var version string
Expand Down Expand Up @@ -85,7 +85,6 @@ func main() {
}
}


config, err := dbanon.NewConfig(*requested)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand All @@ -97,7 +96,7 @@ func main() {
// We don't want to hear about it
log.SetOutput(ioutil.Discard)
reader := bufio.NewReader(os.Stdin)

args := flag.Args()
mode := "anonymize"
if len(args) > 0 && args[0] == "map-eav" {
Expand All @@ -108,7 +107,6 @@ func main() {
eav := dbanon.NewEav(config)
processor := dbanon.NewLineProcessor(mode, config, provider, eav)


for {
text, err := reader.ReadString('\n')
result := processor.ProcessLine(text)
Expand All @@ -126,4 +124,4 @@ func main() {
fmt.Print(string(out))
os.Exit(0)
}
}
}
11 changes: 5 additions & 6 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

type Config struct {
Tables []struct {
Name string `yaml:"name"`
Name string `yaml:"name"`
Columns map[string]string `yaml:"columns"`
}
Eav []struct {
Name string `yaml:"name"`
Name string `yaml:"name"`
Attributes map[string]string `yaml:"attributes"`
}
}
Expand Down Expand Up @@ -48,10 +48,9 @@ func (c Config) String() ([]byte, error) {
return yaml.Marshal(c)
}


func (c Config) ProcessTable(t string) string {
for _, table := range c.Tables {
if (table.Name == t) {
if table.Name == t {
return "table"
}
}
Expand All @@ -74,7 +73,7 @@ func (c Config) ProcessTable(t string) string {

func (c Config) ProcessColumn(t string, col string) (bool, string) {
for _, table := range c.Tables {
if (table.Name != t) {
if table.Name != t {
continue
}

Expand Down Expand Up @@ -102,4 +101,4 @@ func (c Config) ProcessEav(t string, attributeId string) (bool, string) {
}

return false, ""
}
}
2 changes: 1 addition & 1 deletion src/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ func TestProcessEav(t *testing.T) {
if format2 != "" {
t.Errorf("Got %s want empty string", format2)
}
}
}
2 changes: 1 addition & 1 deletion src/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ func findNextTable(s string) {
if k == 0 {
nextTable += s
}
}
}
6 changes: 3 additions & 3 deletions src/eav.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dbanon

type Eav struct{
Config *Config
type Eav struct {
Config *Config
entityMap map[string]string
}

Expand All @@ -10,4 +10,4 @@ func NewEav(c *Config) *Eav {
e := &Eav{Config: c, entityMap: made}

return e
}
}
2 changes: 1 addition & 1 deletion src/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func SetLogger(l *logrus.Logger) {

func GetLogger() *logrus.Logger {
return logger
}
}
12 changes: 6 additions & 6 deletions src/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

type LineProcessor struct {
Mode string
Config *Config
Mode string
Config *Config
Provider ProviderInterface
Eav *Eav
Eav *Eav
}

func NewLineProcessor(m string, c *Config, p ProviderInterface, e *Eav) *LineProcessor {
Expand Down Expand Up @@ -44,7 +44,7 @@ func (p LineProcessor) processInsert(s string) string {
var dataType string

var entityTypeId string

rows := insert.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
Expand All @@ -65,7 +65,7 @@ func (p LineProcessor) processInsert(s string) string {
} else {
if column == "attribute_id" {
attributeId = string(v.Val)
if (p.Mode == "anonymize") {
if p.Mode == "anonymize" {
result, dataType = p.Config.ProcessEav(table, attributeId)
}
}
Expand Down Expand Up @@ -97,4 +97,4 @@ func (p LineProcessor) processInsert(s string) string {
}

return sqlparser.String(insert) + ";\n"
}
}
9 changes: 4 additions & 5 deletions src/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestProcessLine(t *testing.T) {
processor.ProcessLine(" `firstname` varchar(32) DEFAULT NULL COMMENT 'User First Name'")
processor.ProcessLine(") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='Admin User Table'")
processor.ProcessLine("/*!40101 SET character_set_client = @saved_cs_client */;")

r2 := processor.ProcessLine("INSERT INTO `admin_user` (`firstname`) VALUES ('bob');")
if strings.Contains(r2, "bob") {
t.Error("Got bob wanted no bob")
Expand Down Expand Up @@ -89,14 +89,13 @@ func TestEavProcessLine(t *testing.T) {
eav := NewEav(config)
processor := NewLineProcessor(mode, config, provider, eav)


processor.ProcessLine("CREATE TABLE `eav_entity_type` (")
processor.ProcessLine(" `entity_type_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Type ID',")
processor.ProcessLine(" `entity_type_code` varchar(50) NOT NULL COMMENT 'Entity Type Code'")
processor.ProcessLine(") ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='Eav Entity Type';")
processor.ProcessLine("/*!40101 SET character_set_client = @saved_cs_client */;")
processor.ProcessLine("INSERT INTO `eav_entity_type` (`entity_type_id`, `entity_type_code`) VALUES (1, 'customer');")

processor.ProcessLine("CREATE TABLE `eav_attribute` (")
processor.ProcessLine(" `attribute_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Attribute ID',")
processor.ProcessLine(" `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type ID',")
Expand Down Expand Up @@ -124,6 +123,6 @@ func TestEavProcessLine(t *testing.T) {

if !r2 {
t.Errorf("Got false wanted true")
}
}

}
}
16 changes: 8 additions & 8 deletions src/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

var fakeEmail = faker.Internet().Email

var rawProviders = map[string]interface{} {
"Lorem()": faker.Lorem(),
var rawProviders = map[string]interface{}{
"Lorem()": faker.Lorem(),
"Internet()": faker.Internet(),
"Commerce()": faker.Commerce(),
"Code()": faker.Code(),
"Number()": faker.Number(),
"Code()": faker.Code(),
"Number()": faker.Number(),
}

type Provider struct{
type Provider struct {
providedUniqueEmails map[string]int
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func (p Provider) Get(s string) string {
return ""
}

func (p Provider) raw (s string) string {
func (p Provider) raw(s string) string {
logger := GetLogger()
parts := strings.Split(s, ".")

Expand All @@ -132,7 +132,7 @@ func (p Provider) raw (s string) string {
return ""
}

args := parts[2][argsStart + 1 : argsEnd]
args := parts[2][argsStart+1 : argsEnd]
if args == "" {
out := method.Call(nil)
return out[0].String()
Expand All @@ -147,4 +147,4 @@ func (p Provider) raw (s string) string {
out := method.Call(in)
return out[0].String()
}
}
}
4 changes: 2 additions & 2 deletions src/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestGet(t *testing.T) {
t.Errorf("Unsupported method not handled correctly")
}

_ = provider.Get("faker.Internet().Slug")
_ = provider.Get("faker.Internet().Slug")
if hook.LastEntry().Message != "Could not identify arguments for Slug" {
t.Errorf("Malformed arguments not handled correctly")
}
}
}

0 comments on commit 487421a

Please sign in to comment.