Skip to content

Commit 347ab8f

Browse files
committed
fixup! RHINENG-20967: test candlepin environment assignment
1 parent 3470c83 commit 347ab8f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

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+
}

0 commit comments

Comments
 (0)