Skip to content

Commit 237733d

Browse files
committed
RHINENG-20967: test candlepin environment assignment
1 parent 187bcd9 commit 237733d

3 files changed

Lines changed: 83 additions & 23 deletions

File tree

docker-compose.test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ services:
4343
env_file:
4444
- ./conf/common.env
4545
- ./conf/platform.env
46+
- ./conf/gorun.env
4647
command: ./dev/scripts/docker-compose-entrypoint.sh platform
4748
restart: unless-stopped
4849
ports:
4950
- 9001:9001
5051
- 9005:9005
5152
volumes:
53+
- ./:/go/src/app/
5254
- ./conf/cdappconfig.json:/go/src/app/conf/cdappconfig.json
5355
depends_on:
5456
- kafka

listener/rhsm_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"app/base/core"
55
"app/base/database"
66
"app/base/utils"
7+
"context"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -48,3 +49,38 @@ func TestAssignTemplates(t *testing.T) {
4849
})
4950
}
5051
}
52+
53+
func TestCallCandlepinEnvironment(t *testing.T) {
54+
ctx := context.Background()
55+
result, err := callCandlepinEnvironment(ctx, "00000000-0000-0000-0000-000000000001")
56+
57+
assert.NoError(t, err)
58+
assert.NotNil(t, result)
59+
assert.Len(t, result.Environments, 1)
60+
assert.Equal(t, "99900000000000000000000000000001", result.Environments[0].ID)
61+
}
62+
63+
func TestCallCandlepinEnvironmentError(t *testing.T) {
64+
ctx := context.Background()
65+
result, err := callCandlepinEnvironment(ctx, "return_404")
66+
67+
assert.Error(t, err)
68+
assert.Contains(t, err.Error(), "candlepin /consumers call failed")
69+
assert.Nil(t, result)
70+
}
71+
72+
func TestCallCandlepinEnvNetworkError(t *testing.T) {
73+
// Override the candlepin address to invalid URL
74+
originalAddress := utils.CoreCfg.CandlepinAddress
75+
utils.CoreCfg.CandlepinAddress = "http://invalid-host:12345"
76+
defer func() {
77+
utils.CoreCfg.CandlepinAddress = originalAddress
78+
}()
79+
80+
ctx := context.Background()
81+
result, err := callCandlepinEnvironment(ctx, "test-consumer")
82+
83+
assert.Error(t, err)
84+
assert.Contains(t, err.Error(), "candlepin error")
85+
assert.Nil(t, result)
86+
}

listener/upload_test.go

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/stretchr/testify/assert"
2222
)
2323

24+
var accountID = int(1)
25+
2426
func 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+
5571
func 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

Comments
 (0)