Skip to content

Commit 60643d7

Browse files
committed
RHINENG-17345: add tests for candlepin env check
1 parent 656013f commit 60643d7

2 files changed

Lines changed: 64 additions & 3 deletions

File tree

listener/upload_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,48 @@ func TestGetRepoPath(t *testing.T) {
429429
assert.Nil(t, err)
430430
assert.Equal(t, "/content/dist/rhel8/rhui/8.4/x86_64/baseos/os", repoPath)
431431
}
432+
433+
func TestHostTemplateRhsmReporter(t *testing.T) {
434+
utils.SkipWithoutDB(t)
435+
core.SetupTestEnvironment()
436+
configure()
437+
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+
449+
templateID := hostTemplate(database.DB, accountID, host)
450+
assert.NotNil(t, templateID)
451+
assert.Equal(t, int64(1), *templateID)
452+
}
453+
454+
func TestHostTemplatePuptoo(t *testing.T) {
455+
utils.SkipWithoutDB(t)
456+
core.SetupTestEnvironment()
457+
configure()
458+
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+
YumRepos: &[]inventory.YumRepo{{
466+
ID: "base",
467+
Enabled: true,
468+
BaseURL: "https://cert.console.example.com/api/pulp-content/abcdef/templates/" +
469+
"12345678-90ab-cdef-1234-567890abcdef/content/dist/rhel9/$releasever/x86_64/baseos/os"}},
470+
},
471+
}
472+
473+
templateID := hostTemplate(database.DB, accountID, host)
474+
assert.NotNil(t, templateID)
475+
assert.Equal(t, int64(2), *templateID)
476+
}

platform/candlepin.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package platform
22

33
import (
4+
"app/base/candlepin"
45
"app/base/utils"
56
"fmt"
67
"io"
78
"net/http"
9+
"strings"
810

911
"github.com/gin-gonic/gin"
1012
)
@@ -30,18 +32,32 @@ func candlepinEnvHandler(c *gin.Context) {
3032
c.Data(http.StatusOK, gin.MIMEJSON, []byte(data))
3133
}
3234

33-
func candlepinConsumersHandler(c *gin.Context) {
35+
func candlepinConsumersPutHandler(c *gin.Context) {
3436
consumer := c.Param("consumer")
3537
jsonData, _ := io.ReadAll(c.Request.Body)
36-
utils.LogInfo("consumer", consumer, "body", string(jsonData))
38+
utils.LogInfo("PUT consumer", consumer, "body", string(jsonData))
3739
if consumer == "return_404" {
3840
c.Data(http.StatusNotFound, gin.MIMEJSON, []byte{})
3941
return
4042
}
4143
c.Data(http.StatusOK, gin.MIMEJSON, []byte{})
4244
}
4345

46+
func candlepinConsumersGetHandler(c *gin.Context) {
47+
consumer := c.Param("consumer")
48+
utils.LogInfo("GET consumer", consumer, "body")
49+
env := strings.ReplaceAll(consumer, "-", "")
50+
env = strings.Replace(env, "000", "999", 1)
51+
response := candlepin.ConsumersDetailResponse{
52+
Environments: []candlepin.ConsumersEnvironment{
53+
{ID: env},
54+
},
55+
}
56+
c.JSON(http.StatusOK, response)
57+
}
58+
4459
func initCandlepin(app *gin.Engine) {
4560
app.POST("/candlepin/environments/:envid/consumers", candlepinEnvHandler)
46-
app.PUT("/candlepin/consumers/:consumer", candlepinConsumersHandler)
61+
app.PUT("/candlepin/consumers/:consumer", candlepinConsumersPutHandler)
62+
app.GET("/candlepin/consumers/:consumer", candlepinConsumersGetHandler)
4763
}

0 commit comments

Comments
 (0)