From 38dd689d3ac12d19605d3918ecbeea7c809dc2a7 Mon Sep 17 00:00:00 2001 From: Sebastian Nickel Date: Mon, 22 Apr 2024 10:48:27 +0200 Subject: [PATCH] improve test --- update/mysql_test.go | 112 ++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 66 deletions(-) diff --git a/update/mysql_test.go b/update/mysql_test.go index ef80ce6..0eba1ef 100644 --- a/update/mysql_test.go +++ b/update/mysql_test.go @@ -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 {