Skip to content

Commit

Permalink
removed testutil prefixes from unit test table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unmarshall committed Jul 11, 2023
1 parent 401edf5 commit 40c8c89
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
30 changes: 15 additions & 15 deletions internal/app/readycheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func testQueryEtcdReadiness(t *testing.T) {
querySuccess bool
expectStatus bool
}{
{"testutil: etcd ready status should be set to true when etcd query succeeds", true, true},
{"testutil: etcd ready status should be set to false when etcd query fails", false, false},
{"etcd ready status should be set to true when etcd query succeeds", true, true},
{"etcd ready status should be set to false when etcd query fails", false, false},
}

for _, entry := range table {
Expand Down Expand Up @@ -99,8 +99,8 @@ func testReadinessHandler(t *testing.T) {
readyStatus bool
expectedStatus int
}{
{"testutil: should return http.StatusOK when etcdStatus.Ready is set to true", true, http.StatusOK},
{"testutil: should return http.StatusServiceUnavailable when etcdStatus.Ready is set to false", false, http.StatusServiceUnavailable},
{"should return http.StatusOK when etcdStatus.Ready is set to true", true, http.StatusOK},
{"should return http.StatusServiceUnavailable when etcdStatus.Ready is set to false", false, http.StatusServiceUnavailable},
}

for _, entry := range table {
Expand Down Expand Up @@ -131,12 +131,12 @@ func testCreateEtcdClient(t *testing.T) {
expectError bool
endpointScheme string
}{
{"testutil: should return valid etcd client with HTTP scheme when no certificates are passed", "", "", "", false, "http"},
{"testutil: should return valid etcd client with HTTPS scheme when all certificates are passed", etcdCertFilePath, etcdKeyFilePath, etcdCACertFilePath, false, "https"},
{"testutil: should return valid etcd client with HTTP scheme when empty certificate file path is passed", "", etcdKeyFilePath, etcdCACertFilePath, false, "http"},
{"testutil: should return valid etcd client with HTTP scheme when empty key file path is passed", etcdCertFilePath, "", etcdCACertFilePath, false, "http"},
{"testutil: should return valid etcd client with HTTP scheme when empty CA cert file path is passed", etcdCertFilePath, etcdKeyFilePath, "", false, "http"},
{"testutil: should return error when wrong certificate file path is passed", filepath.Join(testdataPath, "does-not-exist.crt"), etcdKeyFilePath, etcdCACertFilePath, true, ""},
{"should return valid etcd client with HTTP scheme when no certificates are passed", "", "", "", false, "http"},
{"should return valid etcd client with HTTPS scheme when all certificates are passed", etcdCertFilePath, etcdKeyFilePath, etcdCACertFilePath, false, "https"},
{"should return valid etcd client with HTTP scheme when empty certificate file path is passed", "", etcdKeyFilePath, etcdCACertFilePath, false, "http"},
{"should return valid etcd client with HTTP scheme when empty key file path is passed", etcdCertFilePath, "", etcdCACertFilePath, false, "http"},
{"should return valid etcd client with HTTP scheme when empty CA cert file path is passed", etcdCertFilePath, etcdKeyFilePath, "", false, "http"},
{"should return error when wrong certificate file path is passed", filepath.Join(testdataPath, "does-not-exist.crt"), etcdKeyFilePath, etcdCACertFilePath, true, ""},
}

g := NewWithT(t)
Expand Down Expand Up @@ -171,11 +171,11 @@ func testIsTLSEnabled(t *testing.T) {
trustedCAFilePath string
expectedResult bool
}{
{"testutil: should return true when all files are present", "testutil/path/for/certFile", "testutil/path/for/keyFile", "testutil/path/for/trustedCAFile", true},
{"testutil: should return false when only certFile is not present", "", "testutil/path/for/keyFile", "testutil/path/for/trustedCAFile", false},
{"testutil: should return false when only keyFile is not present", "testutil/path/for/certFile", "", "testutil/path/for/trustedCAFile", false},
{"testutil: should return false when only trusterCAFile is not present", "testutil/path/for/certFile", "testutil/path/for/keyFile", "", false},
{"testutil: should return true when all files not are present", "", "", "", false},
{"should return true when all files are present", "testutil/path/for/certFile", "testutil/path/for/keyFile", "testutil/path/for/trustedCAFile", true},
{"should return false when only certFile is not present", "", "testutil/path/for/keyFile", "testutil/path/for/trustedCAFile", false},
{"should return false when only keyFile is not present", "testutil/path/for/certFile", "", "testutil/path/for/trustedCAFile", false},
{"should return false when only trusterCAFile is not present", "testutil/path/for/certFile", "testutil/path/for/keyFile", "", false},
{"should return true when all files not are present", "", "", "", false},
}

for _, entry := range table {
Expand Down
18 changes: 9 additions & 9 deletions internal/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func TestGetValidationMode(t *testing.T) {
exitCode string
expectedValidationMode brclient.ValidationType
}{
{"testutil: exit code file not being present should result in full validation", "", brclient.FullValidation},
{"testutil: exit code having error string `interrupt` should result in sanity validation", os.Interrupt.String(), brclient.SanityValidation},
{"testutil: exit code having error string `terminated` should result in sanity validation", syscall.SIGTERM.String(), brclient.SanityValidation},
{"testutil: exit code having any other error string should result in full validation", "testutil", brclient.FullValidation},
{"exit code file not being present should result in full validation", "", brclient.FullValidation},
{"exit code having error string `interrupt` should result in sanity validation", os.Interrupt.String(), brclient.SanityValidation},
{"exit code having error string `terminated` should result in sanity validation", syscall.SIGTERM.String(), brclient.SanityValidation},
{"exit code having any other error string should result in full validation", "testutil", brclient.FullValidation},
}
for _, entry := range table {
testDir := createTestDir(t)
Expand Down Expand Up @@ -162,8 +162,8 @@ func TestTryGetEtcdConfig(t *testing.T) {
serverReturnsError bool
expectError bool
}{
{"testutil: should not return error when etcd config is returned", false, false},
{"testutil: should return error when invalid etcd config is returned", true, true},
{"should not return error when etcd config is returned", false, false},
{"should return error when invalid etcd config is returned", true, true},
}
for _, entry := range table {
testDir := createTestDir(t)
Expand Down Expand Up @@ -200,9 +200,9 @@ func TestNewEtcdInitializer(t *testing.T) {
sidecarConfig types.BackupRestoreConfig
expectError bool
}{
{"testutil: should return error when invalid sidecar config is passed", createSidecarConfig(true, "", ""), true},
{"testutil: should return error when br client creation fails", createSidecarConfig(true, ":2379", "/wrong/file/path"), true},
{"testutil: should not return error when sidecar config is valid and br client creation succeeds", createSidecarConfig(false, ":2379", ""), false},
{"should return error when invalid sidecar config is passed", createSidecarConfig(true, "", ""), true},
{"should return error when br client creation fails", createSidecarConfig(true, ":2379", "/wrong/file/path"), true},
{"should not return error when sidecar config is valid and br client creation succeeds", createSidecarConfig(false, ":2379", ""), false},
}

for _, entry := range table {
Expand Down
38 changes: 19 additions & 19 deletions internal/brclient/brclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ func testGetEtcdConfig(t *testing.T, etcdConfigFilePath string) {
validSidecarBaseAddress bool
expectError bool
}{
{"testutil: 200 response code should return a valid etcd config", http.StatusOK, []byte("give me a valid etcd config"), true, false},
{"testutil: 202 response code should return a valid etcd config", http.StatusAccepted, []byte("give me a valid etcd config"), true, false},
{"testutil: 201 response code should return a valid etcd config", http.StatusCreated, []byte("give me a valid etcd config"), true, false},
{"testutil: 208 response code should return an error", http.StatusAlreadyReported, []byte("give me a valid etcd config"), true, true},
{"testutil: 400 response code should return an error", http.StatusBadRequest, []byte("give me a valid etcd config"), true, true},
{"testutil: should return an error when sidecar base address is invalid", http.StatusBadRequest, []byte("invalid server response"), false, true},
{"200 response code should return a valid etcd config", http.StatusOK, []byte("give me a valid etcd config"), true, false},
{"202 response code should return a valid etcd config", http.StatusAccepted, []byte("give me a valid etcd config"), true, false},
{"201 response code should return a valid etcd config", http.StatusCreated, []byte("give me a valid etcd config"), true, false},
{"208 response code should return an error", http.StatusAlreadyReported, []byte("give me a valid etcd config"), true, true},
{"400 response code should return an error", http.StatusBadRequest, []byte("give me a valid etcd config"), true, true},
{"should return an error when sidecar base address is invalid", http.StatusBadRequest, []byte("invalid server response"), false, true},
}

g := NewWithT(t)
Expand Down Expand Up @@ -115,12 +115,12 @@ func testGetInitializationStatus(t *testing.T, etcdConfigFilePath string) {
expectError bool
expectedStatus InitStatus
}{
{"test: New initialization status returned by server should result in New", http.StatusOK, []byte(New.String()), true, false, New},
{"test: InProgress initialization status returned by server should result in InProgress", http.StatusOK, []byte(InProgress.String()), true, false, InProgress},
{"test: Successful initialization status returned by server should result in Successful", http.StatusOK, []byte(Successful.String()), true, false, Successful},
{"test: Unknown initialization status returned by server should result in InProgress", http.StatusOK, []byte("error response"), true, false, InProgress},
{"test: Bad response from server should result in Unknown", http.StatusBadRequest, []byte("error response"), true, true, Unknown},
{"test: When sidecar base address is invalid should return an error and result in Unknown", http.StatusBadRequest, []byte("error response"), false, true, Unknown},
{"New initialization status returned by server should result in New", http.StatusOK, []byte(New.String()), true, false, New},
{"InProgress initialization status returned by server should result in InProgress", http.StatusOK, []byte(InProgress.String()), true, false, InProgress},
{"Successful initialization status returned by server should result in Successful", http.StatusOK, []byte(Successful.String()), true, false, Successful},
{"Unknown initialization status returned by server should result in InProgress", http.StatusOK, []byte("error response"), true, false, InProgress},
{"Bad response from server should result in Unknown", http.StatusBadRequest, []byte("error response"), true, true, Unknown},
{"When sidecar base address is invalid should return an error and result in Unknown", http.StatusBadRequest, []byte("error response"), false, true, Unknown},
}

g := NewWithT(t)
Expand Down Expand Up @@ -149,9 +149,9 @@ func testTriggerInitialization(t *testing.T, etcdConfigFilePath string) {
validSidecarBaseAddress bool
expectError bool
}{
{"testutil: server returning a valid response should not result in an error", http.StatusOK, []byte("valid server response"), true, false},
{"testutil: server returning an error code should result in an error", http.StatusBadRequest, []byte("invalid server response"), true, true},
{"testutil: should return an error when sidecar base address is invalid", http.StatusBadRequest, []byte("invalid server response"), false, true},
{"server returning a valid response should not result in an error", http.StatusOK, []byte("valid server response"), true, false},
{"server returning an error code should result in an error", http.StatusBadRequest, []byte("invalid server response"), true, true},
{"should return an error when sidecar base address is invalid", http.StatusBadRequest, []byte("invalid server response"), false, true},
}

for _, entry := range table {
Expand All @@ -178,8 +178,8 @@ func testCreateSidecarClient(t *testing.T, _ string) {
sidecarConfig types.BackupRestoreConfig
expectError bool
}{
{"testutil: return error when incorrect sidecar config (CA filepath) is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: incorrectCAFilePath}, true},
{"testutil: return etcd client when valid sidecar config is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: etcdCACertFilePath}, false},
{"return error when incorrect sidecar config (CA filepath) is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: incorrectCAFilePath}, true},
{"return etcd client when valid sidecar config is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: etcdCACertFilePath}, false},
}
g := NewWithT(t)
for _, entry := range table {
Expand All @@ -196,8 +196,8 @@ func TestNewDefaultClient(t *testing.T) {
sidecarConfig types.BackupRestoreConfig
expectError bool
}{
{"testutil: return error when incorrect sidecar config is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: incorrectCAFilePath}, true},
{"testutil: return backuprestore client when valid sidecar config is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: etcdCACertFilePath}, false},
{"return error when incorrect sidecar config is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: incorrectCAFilePath}, true},
{"return backuprestore client when valid sidecar config is passed", types.BackupRestoreConfig{TLSEnabled: true, CaCertBundlePath: etcdCACertFilePath}, false},
}
g := NewWithT(t)
defer func() {
Expand Down
12 changes: 6 additions & 6 deletions internal/util/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func TestResponseHasOKCode(t *testing.T) {
responseCode int
expectValue bool
}{
{"testutil: 200 response code should return true", http.StatusOK, true},
{"testutil: 201 response code should return true", http.StatusCreated, true},
{"testutil: 202 response code should return true", http.StatusAccepted, true},
{"testutil: 400 response code should return true", http.StatusBadRequest, false},
{"200 response code should return true", http.StatusOK, true},
{"201 response code should return true", http.StatusCreated, true},
{"202 response code should return true", http.StatusAccepted, true},
{"400 response code should return true", http.StatusBadRequest, false},
}

for _, entry := range table {
Expand All @@ -35,8 +35,8 @@ func TestConstructBaseAddress(t *testing.T) {
hostPort string
expectedBaseAddress string
}{
{"testutil: tls is enabled", true, "localhost:8080", "https://localhost:8080"},
{"testutil: tls is disabled", false, ":2379", "http://:2379"},
{"tls is enabled", true, "localhost:8080", "https://localhost:8080"},
{"tls is disabled", false, ":2379", "http://:2379"},
}

for _, entry := range table {
Expand Down
6 changes: 3 additions & 3 deletions internal/util/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func TestCreateCACertPool(t *testing.T) {
trustedCAFilePath string
expectError bool
}{
{"testutil: should return error when empty ca cert file path is passed", "", true},
{"testutil: should return error when wrong ca cert file path is passed", testdataPath + "/wrong-path", true},
{"testutil: should not return error when valid ca cert file path is passed", etcdCACertFilePath, false},
{"should return error when empty ca cert file path is passed", "", true},
{"should return error when wrong ca cert file path is passed", testdataPath + "/wrong-path", true},
{"should not return error when valid ca cert file path is passed", etcdCACertFilePath, false},
}
g := NewWithT(t)
defer func() {
Expand Down

0 comments on commit 40c8c89

Please sign in to comment.