Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
thirdeyenick committed Apr 22, 2024
1 parent e342021 commit 38dd689
Showing 1 changed file with 46 additions and 66 deletions.
112 changes: 46 additions & 66 deletions update/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,97 +21,77 @@ func TestMySQL(t *testing.T) {
want storage.MySQLParameters
wantErr bool
}{
{"simple", storage.MySQLParameters{}, mySQLCmd{}, storage.MySQLParameters{}, false},
{
"machineType",
storage.MySQLParameters{},
mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))},
storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1")},
false,
name: "simple",
},
{
"machineType",
storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-2")},
mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))},
storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1")},
false,
name: "increase-machineType",
update: mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))},
want: storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1")},
},
{
"sqlMode",
storage.MySQLParameters{},
mySQLCmd{SQLMode: ptr.To([]storage.MySQLMode{"ERROR_FOR_DIVISION_BY_ZERO"})},
storage.MySQLParameters{SQLMode: &[]storage.MySQLMode{"ERROR_FOR_DIVISION_BY_ZERO"}},
false,
name: "decrease-machineType",
create: storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-2")},
update: mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))},
want: storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1")},
},
{
"sqlMode",
storage.MySQLParameters{SQLMode: &[]storage.MySQLMode{"ERROR_FOR_DIVISION_BY_ZERO"}},
mySQLCmd{SQLMode: ptr.To([]storage.MySQLMode{"ALLOW_INVALID_DATES", "STRICT_TRANS_TABLES"})},
storage.MySQLParameters{SQLMode: &[]storage.MySQLMode{"ALLOW_INVALID_DATES", "STRICT_TRANS_TABLES"}},
false,
name: "sqlMode-no-mode-set-initially",
update: mySQLCmd{SQLMode: ptr.To([]storage.MySQLMode{"ERROR_FOR_DIVISION_BY_ZERO"})},
want: storage.MySQLParameters{SQLMode: &[]storage.MySQLMode{"ERROR_FOR_DIVISION_BY_ZERO"}},
},
{
"sshKeys",
storage.MySQLParameters{},
mySQLCmd{SSHKeys: []storage.SSHKey{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJGG5/nnivrW4zLD4ANLclVT3y68GAg6NOA3HpzFLo5e test@test"}},
storage.MySQLParameters{SSHKeys: []storage.SSHKey{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJGG5/nnivrW4zLD4ANLclVT3y68GAg6NOA3HpzFLo5e test@test"}},
false,
name: "sqlMode-initially-set",
create: storage.MySQLParameters{SQLMode: &[]storage.MySQLMode{"ERROR_FOR_DIVISION_BY_ZERO"}},
update: mySQLCmd{SQLMode: ptr.To([]storage.MySQLMode{"ALLOW_INVALID_DATES", "STRICT_TRANS_TABLES"})},
want: storage.MySQLParameters{SQLMode: &[]storage.MySQLMode{"ALLOW_INVALID_DATES", "STRICT_TRANS_TABLES"}},
},
{
"characterSet",
storage.MySQLParameters{},
mySQLCmd{CharacterSetName: ptr.To("latin1"), CharacterSetCollation: ptr.To("latin1-general-ci")},
storage.MySQLParameters{CharacterSet: storage.MySQLCharacterSet{Name: "latin1", Collation: "latin1-general-ci"}},
false,
name: "sshKeys",
update: mySQLCmd{SSHKeys: []storage.SSHKey{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJGG5/nnivrW4zLD4ANLclVT3y68GAg6NOA3HpzFLo5e test@test"}},
want: storage.MySQLParameters{SSHKeys: []storage.SSHKey{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJGG5/nnivrW4zLD4ANLclVT3y68GAg6NOA3HpzFLo5e test@test"}},
},
{
"longQueryTime",
storage.MySQLParameters{},
mySQLCmd{LongQueryTime: ptr.To(storage.LongQueryTime("300"))},
storage.MySQLParameters{LongQueryTime: storage.LongQueryTime("300")},
false,
name: "characterSet",
update: mySQLCmd{CharacterSetName: ptr.To("latin1"), CharacterSetCollation: ptr.To("latin1-general-ci")},
want: storage.MySQLParameters{CharacterSet: storage.MySQLCharacterSet{Name: "latin1", Collation: "latin1-general-ci"}},
},
{
"minWordLength",
storage.MySQLParameters{},
mySQLCmd{MinWordLength: ptr.To(5)},
storage.MySQLParameters{MinWordLength: ptr.To(5)},
false,
name: "longQueryTime",
update: mySQLCmd{LongQueryTime: ptr.To(storage.LongQueryTime("300"))},
want: storage.MySQLParameters{LongQueryTime: storage.LongQueryTime("300")},
},
{
"transactionIsolation",
storage.MySQLParameters{},
mySQLCmd{TransactionIsolation: ptr.To(storage.MySQLTransactionCharacteristic("READ-UNCOMMITTED"))},
storage.MySQLParameters{TransactionIsolation: storage.MySQLTransactionCharacteristic("READ-UNCOMMITTED")},
false,
name: "minWordLength",
update: mySQLCmd{MinWordLength: ptr.To(5)},
want: storage.MySQLParameters{MinWordLength: ptr.To(5)},
},
{
"keepDailyBackups",
storage.MySQLParameters{},
mySQLCmd{KeepDailyBackups: ptr.To(5)},
storage.MySQLParameters{KeepDailyBackups: ptr.To(5)},
false,
name: "transactionIsolation",
update: mySQLCmd{TransactionIsolation: ptr.To(storage.MySQLTransactionCharacteristic("READ-UNCOMMITTED"))},
want: storage.MySQLParameters{TransactionIsolation: storage.MySQLTransactionCharacteristic("READ-UNCOMMITTED")},
},
{
"allowedCIDRs",
storage.MySQLParameters{},
mySQLCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
false,
name: "keepDailyBackups",
update: mySQLCmd{KeepDailyBackups: ptr.To(5)},
want: storage.MySQLParameters{KeepDailyBackups: ptr.To(5)},
},
{
"allowedCIDRs",
storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{"192.168.0.1/24"}},
mySQLCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
false,
name: "allowedCIDRs-nothing-set-initially",
update: mySQLCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
want: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
},
{
"allowedCIDRs",
storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{"0.0.0.0/0"}},
mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))},
storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1"), AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
false,
name: "allowedCIDRs-set-initially",
create: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{"192.168.0.1/24"}},
update: mySQLCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
want: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
},
{
name: "multi-update",
create: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{"0.0.0.0/0"}},
update: mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))},
want: storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1"), AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}},
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 38dd689

Please sign in to comment.