Skip to content

Commit

Permalink
Tests: Replace FailOnError with own implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolGuy committed Aug 16, 2024
1 parent 0f547d8 commit f0f471b
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 212 deletions.
30 changes: 14 additions & 16 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ package cobblerclient
import (
"reflect"
"testing"

"github.com/ContainerSolutions/go-utils"
)

func TestSync(t *testing.T) {
c := createStubHTTPClient(t, "sync-req.xml", "sync-res.xml")

err := c.Sync()
utils.FailOnError(t, err)
FailOnError(t, err)
}

func TestBackgroundSync(t *testing.T) {
c := createStubHTTPClient(t, "background-sync-req.xml", "background-sync-res.xml")

res, err := c.BackgroundSync(BackgroundSyncOptions{Dhcp: false, Dns: false, Verbose: false})
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2022-09-30_145124_Sync_2cabdc4eddfa4731b45f145d7b625e29" {
t.Errorf("Problem with event id return")
}
Expand All @@ -28,7 +26,7 @@ func TestBackgroundSyncSystems(t *testing.T) {
c := createStubHTTPClient(t, "background-sync-systems-req.xml", "background-sync-systems-res.xml")

res, err := c.BackgroundSyncSystems(BackgroundSyncSystemsOptions{Systems: []string{"", ""}, Verbose: false})
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2022-09-30_151856_Syncsystems_76d70bd7f48642f7b4cb5a0b0dcc93a5" {
t.Errorf("Problem with event id return")
}
Expand All @@ -40,7 +38,7 @@ func TestCheck(t *testing.T) {

result, err := c.Check()
var resolvedResult = *result
utils.FailOnError(t, err)
FailOnError(t, err)

if !reflect.DeepEqual(resolvedResult, expected) {
t.Errorf("%s expected; got %s", expected, result)
Expand All @@ -62,7 +60,7 @@ func TestBackgroundBuildiso(t *testing.T) {
ExcludeDns: false,
XorrisofsOpts: "",
})
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2023-01-24_083001_Build Iso_20fa7d4256fc4f61a2b9c2237c80fb41" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -72,7 +70,7 @@ func TestBackgroundHardlink(t *testing.T) {
c := createStubHTTPClient(t, "background-hardlink-req.xml", "background-hardlink-res.xml")

res, err := c.BackgroundHardlink()
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2022-09-30_203004_Hardlink_800c38f4e0424187aed6a6ffb6553ef8" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -86,7 +84,7 @@ func TestValidateAutoinstallFiles(t *testing.T) {
)

res, err := c.BackgroundValidateAutoinstallFiles()
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2022-09-30_203505_Automated installation files validation_487b1a5d1d914c62834126391ac2b601" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -111,7 +109,7 @@ func TestBackgroundReplicate(t *testing.T) {
SyncAll: false,
UseSsl: false,
})
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2023-01-24_075801_Replicate_ea7a003a81264039b4277ac55664661a" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -129,7 +127,7 @@ func TestBackgroundAclSetup(t *testing.T) {
if res != "2023-01-24_083137_(CLI) ACL Configuration_334327920d2946fda3ac95dbf457e76d" {
t.Errorf("Event-ID was malformed")
}
utils.FailOnError(t, err)
FailOnError(t, err)
}

func TestBackgroundImport(t *testing.T) {
Expand All @@ -145,7 +143,7 @@ func TestBackgroundImport(t *testing.T) {
Breed: "",
OsVersion: "",
})
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2023-01-24_103639_Media import_dd297121f7bc412e9ce4d80f05de4b3f" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -160,7 +158,7 @@ func TestBackgroundReposync(t *testing.T) {
Nofail: false,
Tries: 0,
})
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2023-01-24_103758_Reposync_3478fd19fd5f48bf8b40c728ad247348" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -170,7 +168,7 @@ func TestBackgroundMkLoaders(t *testing.T) {
c := createStubHTTPClient(t, "background-mkloaders-req.xml", "background-mkloaders-res.xml")

res, err := c.BackgroundMkLoaders()
utils.FailOnError(t, err)
FailOnError(t, err)
if res != "2022-09-30_203957_Create bootable bootloader images_9c809af4d6f148e49b071fac84f9a664" {
t.Fatalf("Expected a different Event-ID!")
}
Expand All @@ -183,7 +181,7 @@ func TestBackgroundPowerSystem(t *testing.T) {
Systems: []string{"testsys1"},
Power: "off",
})
utils.FailOnError(t, err)
FailOnError(t, err)
if result != "2024-08-06_072956_Power management ()_1a44f162efa74806b16d055dfad0fc04" {
t.Errorf("Event-ID was malformed")
}
Expand All @@ -193,7 +191,7 @@ func TestPowerSystem(t *testing.T) {
c := createStubHTTPClient(t, "power-system-req.xml", "power-system-res.xml")

result, err := c.PowerSystem("system::testsys1", "status")
utils.FailOnError(t, err)
FailOnError(t, err)
if !result {
t.Errorf("Expected power operation not to fail!")
}
Expand Down
16 changes: 7 additions & 9 deletions authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package cobblerclient

import (
"testing"

"github.com/ContainerSolutions/go-utils"
)

func TestCheckAccessNoFail(t *testing.T) {
c := createStubHTTPClient(t, "check-access-no-fail-req.xml", "check-access-no-fail-res.xml")

res, err := c.CheckAccessNoFail("", "", "")
utils.FailOnError(t, err)
FailOnError(t, err)
if res != false {
t.Errorf(`"%t" expected; got "%t"`, false, res)
}
Expand All @@ -20,7 +18,7 @@ func TestCheckAccess(t *testing.T) {
c := createStubHTTPClient(t, "check-access-req.xml", "check-access-res.xml")

res, err := c.CheckAccess("", "", "")
utils.FailOnError(t, err)
FailOnError(t, err)
if res < 0 || res > 1 {
t.Errorf(`"0" or "1" expected; got "%d"`, res)
}
Expand All @@ -31,7 +29,7 @@ func TestGetAuthnModuleName(t *testing.T) {
var expected = "authentication.configfile"

res, err := c.GetAuthnModuleName()
utils.FailOnError(t, err)
FailOnError(t, err)
if res != expected {
t.Errorf(`"%s" expected; got "%s"`, expected, res)
}
Expand All @@ -40,7 +38,7 @@ func TestGetAuthnModuleName(t *testing.T) {
func TestLogin(t *testing.T) {
c := createStubHTTPClient(t, "login-req.xml", "login-res.xml")
ok, err := c.Login()
utils.FailOnError(t, err)
FailOnError(t, err)

if !ok {
t.Errorf("true expected; got false")
Expand Down Expand Up @@ -71,7 +69,7 @@ func TestLogout(t *testing.T) {
var expected = false

res, err := c.Logout()
utils.FailOnError(t, err)
FailOnError(t, err)
if res != expected {
t.Errorf(`"%t" expected; got "%t"`, expected, res)
}
Expand All @@ -82,7 +80,7 @@ func TestTokenCheck(t *testing.T) {
var expected = false

res, err := c.TokenCheck("my_fake_token")
utils.FailOnError(t, err)
FailOnError(t, err)
if res == expected {
t.Errorf(`"%t" expected; got "%t"`, expected, res)
}
Expand All @@ -93,7 +91,7 @@ func TestGetUserFromToken(t *testing.T) {
var expected = "testuser"

res, err := c.GetUserFromToken("securetoken99")
utils.FailOnError(t, err)
FailOnError(t, err)
if res != expected {
t.Errorf(`"%s" expected; got "%s"`, expected, res)
}
Expand Down
Loading

0 comments on commit f0f471b

Please sign in to comment.