@@ -21,6 +21,8 @@ import (
2121 "github.com/stretchr/testify/assert"
2222)
2323
24+ var accountID = int (1 )
25+
2426func assertInLogs (t * testing.T , msg string , logs ... log.Entry ) {
2527 nLogs := len (logs )
2628 i := 0
@@ -52,6 +54,20 @@ func createTestInvHost(t *testing.T) *Host {
5254 return & host
5355}
5456
57+ func createTestHostWithEnv (reporter , consumer , baseURL string ) * Host {
58+ return & Host {
59+ ID : id ,
60+ Reporter : reporter ,
61+ SystemProfile : inventory.SystemProfile {
62+ ConsumerID : consumer ,
63+ YumRepos : & []inventory.YumRepo {{
64+ ID : "base" ,
65+ Enabled : true ,
66+ BaseURL : baseURL }},
67+ },
68+ }
69+ }
70+
5571func TestUpdateSystemPlatform (t * testing.T ) {
5672 utils .SkipWithoutDB (t )
5773 core .SetupTestEnvironment ()
@@ -435,17 +451,9 @@ func TestHostTemplateRhsmReporter(t *testing.T) {
435451 core .SetupTestEnvironment ()
436452 configure ()
437453
438- accountID := int (1 )
439- host := & Host {
440- ID : id ,
441- Reporter : rhsmReporter ,
442- SystemProfile : inventory.SystemProfile {
443- Rhsm : inventory.Rhsm {
444- Environments : []string {"99900000000000000000000000000001" , "99900000000000000000000000000002" },
445- },
446- },
447- }
448-
454+ host := createTestHostWithEnv (rhsmReporter , "00000000-0000-0000-0000-000000000001" ,
455+ "https://cert.console.example.com/api/pulp-content/abcdef/templates/" +
456+ "12345678-90ab-cdef-1234-567890abcdef/content/dist/rhel9/$releasever/x86_64/baseos/os" )
449457 templateID := hostTemplate (database .DB , accountID , host )
450458 assert .NotNil (t , templateID )
451459 assert .Equal (t , int64 (1 ), * templateID )
@@ -456,19 +464,33 @@ func TestHostTemplatePuptoo(t *testing.T) {
456464 core .SetupTestEnvironment ()
457465 configure ()
458466
459- accountID := int (1 )
460- host := & Host {
461- ID : id ,
462- Reporter : puptooReporter ,
463- SystemProfile : inventory.SystemProfile {
464- ConsumerID : "00000000-0000-0000-0000-000000000002" ,
465- Rhsm : inventory.Rhsm {
466- Environments : []string {"99900000000000000000000000000002" },
467- },
468- },
469- }
470-
467+ host := createTestHostWithEnv (puptooReporter , "00000000-0000-0000-0000-000000000002" ,
468+ "https://cert.console.example.com/api/pulp-content/abcdef/templates/" +
469+ "12345678-90ab-cdef-1234-567890abcdef/content/dist/rhel9/$releasever/x86_64/baseos/os" )
471470 templateID := hostTemplate (database .DB , accountID , host )
472471 assert .NotNil (t , templateID )
473472 assert .Equal (t , int64 (2 ), * templateID )
474473}
474+
475+ func TestNoHostTemplate (t * testing.T ) {
476+ utils .SkipWithoutDB (t )
477+ core .SetupTestEnvironment ()
478+ configure ()
479+
480+ host := createTestHostWithEnv (puptooReporter , "00000000-0000-0000-0000-000000000002" ,
481+ "https://cdn.example.com/content/dist/rhel9/$releasever/x86_64/baseos/os" )
482+ templateID := hostTemplate (database .DB , accountID , host )
483+ assert .Nil (t , templateID )
484+ }
485+
486+ func TestHostTemplateCandlepinFailure (t * testing.T ) {
487+ utils .SkipWithoutDB (t )
488+ core .SetupTestEnvironment ()
489+ configure ()
490+
491+ host := createTestHostWithEnv (puptooReporter , "return_404" ,
492+ "https://cert.console.example.com/api/pulp-content/abcdef/templates/" +
493+ "12345678-90ab-cdef-1234-567890abcdef/content/dist/rhel9/$releasever/x86_64/baseos/os" )
494+ templateID := hostTemplate (database .DB , accountID , host )
495+ assert .Nil (t , templateID )
496+ }
0 commit comments