Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions tests/config_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 IBM Corp.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License

package tests

import (
Expand All @@ -16,18 +30,18 @@ func TestCheckConfig(t *testing.T) {

if cfgTest.shouldSucceed {
if err != nil {
t.Fatal("hdbbackint -check should succeed but failed")
t.Error("hdbbackint -check should succeed but failed")
} else {
t.Log("Config check passed")
}
} else {
if err == nil {
t.Fatal("hdbbackint -check should fail but succeeded")
t.Error("hdbbackint -check should fail but succeeded")
} else {
if errMsgOk(string(output), cfgTest.msgToCheck) {
t.Log("Config check passed")
} else {
t.Fatalf("Wrong error message(s): \nOutput: %s", output)
t.Errorf("Wrong error message(s): \nOutput: %s", output)
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions tests/hdbbackint_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 IBM Corp.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License

package tests

import (
Expand All @@ -9,11 +23,11 @@ import (
func TestVersion(t *testing.T) {
output, err := runCommand(t, getExecutablePath(), "-v")
if err != nil {
t.Fatalf("hdbbackint -v failed: %v\nOutput: %s", err, output)
t.Errorf("hdbbackint -v failed: %v\nOutput: %s", err, output)
}

if len(output) == 0 {
t.Fatal("expected version output, got empty output")
t.Error("expected version output, got empty output")
}

t.Logf("Version output: %s", string(output))
Expand Down
46 changes: 30 additions & 16 deletions tests/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 IBM Corp.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License

package tests

import (
Expand Down Expand Up @@ -43,9 +57,9 @@ func setupTempDir(t *testing.T) string {
}

// createAPIKeyFile creates a dummy API key file in the specified directory
func createAPIKeyFile(t *testing.T, tmpDir string) string {
func createAPIKeyFile(t *testing.T, tempDir string) string {
t.Helper()
apiKeyFile := filepath.Join(tmpDir, "apikey")
apiKeyFile := filepath.Join(tempDir, "apikey")
apikey := os.Getenv("APIKEY")
if apikey == "" {
t.Fatal("APIKEY not set.")
Expand All @@ -57,7 +71,7 @@ func createAPIKeyFile(t *testing.T, tmpDir string) string {
}

// prepareConfigFile reads a config template, replaces placeholders, and writes it to a temp location
func prepareConfigFile(t *testing.T, tmpDir, apiKeyFile string, templateFile string) string {
func prepareConfigFile(t *testing.T, tempDir, apiKeyFile string, templateFile string) string {
t.Helper()
templatePath := filepath.Join(templateDir, templateFile)
cfgFile := strings.ReplaceAll(templateFile, "tpl", "cfg")
Expand All @@ -68,7 +82,7 @@ func prepareConfigFile(t *testing.T, tmpDir, apiKeyFile string, templateFile str

cfgContent := strings.ReplaceAll(string(cfgBytes), apiKeyPlaceholder, apiKeyFile)

cfgPath := filepath.Join(tmpDir, cfgFile)
cfgPath := filepath.Join(tempDir, cfgFile)
if err := os.WriteFile(cfgPath, []byte(cfgContent), 0644); err != nil {
t.Fatalf("failed to write config file: %v", err)
}
Expand All @@ -84,45 +98,45 @@ func getExecutablePath() string {
func setupConfigTests(t *testing.T) []ConfigTest {
t.Helper()

tmpDir := setupTempDir(t)
apiKeyFile := createAPIKeyFile(t, tmpDir)
tempDir := setupTempDir(t)
apiKeyFile := createAPIKeyFile(t, tempDir)

var configTests []ConfigTest

configTests = append(configTests, ConfigTest{
name: "Valid Configuration",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgSuccessFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgSuccessFile),
shouldSucceed: true,
msgToCheck: "",
})

configTests = append(configTests, ConfigTest{
name: "Invalid section",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgWrongSectionFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgWrongSectionFile),
shouldSucceed: false,
msgToCheck: "ERROR: You specified the section 'cloud'," +
" but it is not part of the hdbbackint configuration.",
})

configTests = append(configTests, ConfigTest{
name: "Invalid range",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgwrongRangeFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgwrongRangeFile),
shouldSucceed: false,
msgToCheck: "ERROR: 'max_concurrency':" +
" the value '1234' you specified is invalid.",
})

configTests = append(configTests, ConfigTest{
name: "Invalid object tags",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgWrongObjectTagsFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgWrongObjectTagsFile),
shouldSucceed: false,
msgToCheck: "ERROR: 'object_tags': the value" +
" 'key1,val1,key2=val2' you specified is invalid.",
})

configTests = append(configTests, ConfigTest{
name: "Unknown parameter",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgUnknownParmFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgUnknownParmFile),
shouldSucceed: false,
msgToCheck: "ERROR: You specified 'unknown_key'" +
" in section 'objects', but the key is unknown." +
Expand All @@ -131,7 +145,7 @@ func setupConfigTests(t *testing.T) []ConfigTest {

configTests = append(configTests, ConfigTest{
name: "Parameter in wrong section",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgParmInWrongSectionFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgParmInWrongSectionFile),
shouldSucceed: false,
msgToCheck: "ERROR: You specified 'object_tags' in section" +
" 'cloud_storage', but key belongs to section objects." +
Expand All @@ -140,30 +154,30 @@ func setupConfigTests(t *testing.T) []ConfigTest {

configTests = append(configTests, ConfigTest{
name: "Wrong object lock retention period",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgObjLockWrongPeriodFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgObjLockWrongPeriodFile),
shouldSucceed: false,
msgToCheck: "The value you specified for 'object_lock_retention_period'" +
" does not have the correct format.",
})

configTests = append(configTests, ConfigTest{
name: "Missing object lock retention period",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgObjMissingPeriodFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgObjMissingPeriodFile),
shouldSucceed: false,
msgToCheck: "ERROR: You specified 'object_lock_retention_mode = cmp'," +
" but no 'object_lock_retention_period' is specified.",
})

configTests = append(configTests, ConfigTest{
name: "Missing mandatory parameter",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgMissingMandParmFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgMissingMandParmFile),
shouldSucceed: false,
msgToCheck: "ERROR: You did not specify a value for the mandatory parameter",
})

configTests = append(configTests, ConfigTest{
name: "More than one error",
cfgPath: prepareConfigFile(t, tmpDir, apiKeyFile, cfgMixedErrorFile),
cfgPath: prepareConfigFile(t, tempDir, apiKeyFile, cfgMixedErrorFile),
shouldSucceed: false,
msgToCheck: "ERROR: 'object_tags': the value" +
" 'key1,val1,key2=val2' you specified is invalid.",
Expand Down