Skip to content

Commit 257e9a1

Browse files
committed
v2_test: Add testing for cloudapi /depsolve/blueprint
Test the depsolve using a mocked response, test for mismatched distributions, and for unsupported architectures.
1 parent 793f952 commit 257e9a1

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

internal/cloudapi/v2/v2_test.go

+144
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ func newV2Server(t *testing.T, dir string, depsolveChannels []string, enableJWT
108108
}
109109
dJR := &worker.DepsolveJobResult{
110110
PackageSpecs: map[string][]rpmmd.PackageSpec{
111+
// Used when depsolving a list of packages outside the manifest
112+
// Including it in other responses currently doesn't cause a problem
113+
"depsolve": {
114+
{
115+
Name: "dep-package1",
116+
Version: "1.33",
117+
Release: "2.fc30",
118+
Arch: "x86_64",
119+
Checksum: "sha256:fe3951d112c3b1c84dc8eac57afe0830df72df1ca0096b842f4db5d781189893",
120+
},
121+
},
122+
// Used when depsolving a manifest
111123
"build": {
112124
{
113125
Name: "pkg1",
@@ -1546,3 +1558,135 @@ func TestImageFromCompose(t *testing.T) {
15461558
}
15471559
}`, imgJobId, imgJobId))
15481560
}
1561+
1562+
func TestDepsolveBlueprint(t *testing.T) {
1563+
srv, _, _, cancel := newV2Server(t, t.TempDir(), []string{""}, false, false)
1564+
defer cancel()
1565+
1566+
test.TestRoute(t, srv.Handler("/api/image-builder-composer/v2"), false, "POST",
1567+
"/api/image-builder-composer/v2/depsolve/blueprint", fmt.Sprintf(`
1568+
{
1569+
"blueprint": {
1570+
"name": "deptest1",
1571+
"version": "0.0.1",
1572+
"distro": "%[1]s",
1573+
"packages": [
1574+
{ "name": "dep-package", "version": "*" }
1575+
]},
1576+
"distribution": "%[1]s",
1577+
"architecture": "%[2]s"
1578+
}`, test_distro.TestDistro1Name, test_distro.TestArchName),
1579+
http.StatusOK,
1580+
`{
1581+
"packages": [
1582+
{
1583+
"name": "dep-package1",
1584+
"type": "rpm",
1585+
"version": "1.33",
1586+
"release": "2.fc30",
1587+
"arch": "x86_64",
1588+
"checksum": "sha256:fe3951d112c3b1c84dc8eac57afe0830df72df1ca0096b842f4db5d781189893"
1589+
}
1590+
]
1591+
}`)
1592+
}
1593+
1594+
func TestDepsolveDistroErrors(t *testing.T) {
1595+
srv, _, _, cancel := newV2Server(t, t.TempDir(), []string{""}, false, false)
1596+
defer cancel()
1597+
1598+
// matching distros, but not supported
1599+
test.TestRoute(t, srv.Handler("/api/image-builder-composer/v2"), false, "POST",
1600+
"/api/image-builder-composer/v2/depsolve/blueprint", fmt.Sprintf(`
1601+
{
1602+
"blueprint": {
1603+
"name": "deptest1",
1604+
"version": "0.0.1",
1605+
"distro": "bart",
1606+
"packages": [
1607+
{ "name": "dep-package", "version": "*" }
1608+
]},
1609+
"distribution": "bart",
1610+
"architecture": "%[2]s"
1611+
}`, test_distro.TestDistro1Name, test_distro.TestArchName),
1612+
http.StatusBadRequest, `
1613+
{
1614+
"href": "/api/image-builder-composer/v2/errors/4",
1615+
"id": "4",
1616+
"kind": "Error",
1617+
"code": "IMAGE-BUILDER-COMPOSER-4",
1618+
"reason": "Unsupported distribution"
1619+
}`, "operation_id", "details")
1620+
1621+
// Mismatched distros
1622+
test.TestRoute(t, srv.Handler("/api/image-builder-composer/v2"), false, "POST",
1623+
"/api/image-builder-composer/v2/depsolve/blueprint", fmt.Sprintf(`
1624+
{
1625+
"blueprint": {
1626+
"name": "deptest1",
1627+
"version": "0.0.1",
1628+
"distro": "bart",
1629+
"packages": [
1630+
{ "name": "dep-package", "version": "*" }
1631+
]},
1632+
"distribution": "%[1]s",
1633+
"architecture": "%[2]s"
1634+
}`, test_distro.TestDistro1Name, test_distro.TestArchName),
1635+
http.StatusBadRequest, `
1636+
{
1637+
"href": "/api/image-builder-composer/v2/errors/40",
1638+
"id": "40",
1639+
"kind": "Error",
1640+
"code": "IMAGE-BUILDER-COMPOSER-40",
1641+
"reason": "Invalid request, Blueprint and Cloud API request Distribution must match."
1642+
}`, "operation_id", "details")
1643+
1644+
// Bad distro in request, none in blueprint
1645+
test.TestRoute(t, srv.Handler("/api/image-builder-composer/v2"), false, "POST",
1646+
"/api/image-builder-composer/v2/depsolve/blueprint", fmt.Sprintf(`
1647+
{
1648+
"blueprint": {
1649+
"name": "deptest1",
1650+
"version": "0.0.1",
1651+
"packages": [
1652+
{ "name": "dep-package", "version": "*" }
1653+
]},
1654+
"distribution": "bart",
1655+
"architecture": "%[2]s"
1656+
}`, test_distro.TestDistro1Name, test_distro.TestArchName),
1657+
http.StatusBadRequest, `
1658+
{
1659+
"href": "/api/image-builder-composer/v2/errors/4",
1660+
"id": "4",
1661+
"kind": "Error",
1662+
"code": "IMAGE-BUILDER-COMPOSER-4",
1663+
"reason": "Unsupported distribution"
1664+
}`, "operation_id", "details")
1665+
}
1666+
1667+
func TestDepsolveArchErrors(t *testing.T) {
1668+
srv, _, _, cancel := newV2Server(t, t.TempDir(), []string{""}, false, false)
1669+
defer cancel()
1670+
1671+
// Unsupported architecture
1672+
test.TestRoute(t, srv.Handler("/api/image-builder-composer/v2"), false, "POST",
1673+
"/api/image-builder-composer/v2/depsolve/blueprint", fmt.Sprintf(`
1674+
{
1675+
"blueprint": {
1676+
"name": "deptest1",
1677+
"version": "0.0.1",
1678+
"packages": [
1679+
{ "name": "dep-package", "version": "*" }
1680+
]},
1681+
"distribution": "%[1]s",
1682+
"architecture": "MOS6502",
1683+
}`, test_distro.TestDistro1Name),
1684+
http.StatusBadRequest, `
1685+
{
1686+
"href": "/api/image-builder-composer/v2/errors/30",
1687+
"id": "30",
1688+
"kind": "Error",
1689+
"code": "IMAGE-BUILDER-COMPOSER-30",
1690+
"reason": "Request could not be validated"
1691+
}`, "operation_id", "details")
1692+
}

0 commit comments

Comments
 (0)