Skip to content

Commit

Permalink
feat(sdl): test volumes named correctly within deployment group
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian committed Sep 14, 2023
1 parent 365302a commit 6bf4400
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sdl/_testdata/storageClass6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
version: "2.0"
services:
web:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
params:
storage:
configs:
mount: /test
profiles:
compute:
web:
resources:
cpu:
units: "100m"
memory:
size: "128Mi"
storage:
- size: "1Gi"
- size: 1Gi
name: configs
attributes:
persistent: true
placement:
westcoast:
attributes:
region: us-west
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
web:
denom: uakt
amount: 50
deployment:
web:
westcoast:
profile: web
count: 1
140 changes: 140 additions & 0 deletions sdl/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,143 @@ func TestV2ParseServiceMix2(t *testing.T) {
},
}, mani.GetGroups()[0])
}

func TestV2ParseStorageName(t *testing.T) {
sdl, err := ReadFile("./_testdata/storageClass6.yaml")
require.NoError(t, err)

groups, err := sdl.DeploymentGroups()
require.NoError(t, err)
assert.Len(t, groups, 1)

group := groups[0]
assert.Len(t, group.GetResourceUnits(), 1)
assert.Len(t, group.Requirements.Attributes, 1)

assert.Equal(t, atypes.Attribute{
Key: "region",
Value: "us-west",
}, group.Requirements.Attributes[0])

assert.Equal(t, dtypes.ResourceUnits{
{
Count: 1,
Resources: atypes.Resources{
ID: 1,
CPU: &atypes.CPU{
Units: atypes.NewResourceValue(randCPU),
},
GPU: &atypes.GPU{
Units: atypes.NewResourceValue(0),
},
Memory: &atypes.Memory{
Quantity: atypes.NewResourceValue(randMemory),
},
Storage: atypes.Volumes{
{
Name: "default",
Quantity: atypes.NewResourceValue(randStorage),
},
{
Name: "configs",
Quantity: atypes.NewResourceValue(randStorage),
Attributes: atypes.Attributes{
{
Key: "class",
Value: "default",
},
{
Key: "persistent",
Value: "true",
},
},
},
},
Endpoints: []atypes.Endpoint{
{
Kind: atypes.Endpoint_SHARED_HTTP,
},
{
Kind: atypes.Endpoint_RANDOM_PORT,
},
},
},
Price: AkashDecCoin(t, 50),
},
}, group.GetResourceUnits())

mani, err := sdl.Manifest()
require.NoError(t, err)

assert.Len(t, mani.GetGroups(), 1)

assert.Equal(t, manifest.Group{
Name: "westcoast",
Services: []manifest.Service{
{
Name: "web",
Image: "nginx",
Resources: atypes.Resources{
ID: 1,
CPU: &atypes.CPU{
Units: atypes.NewResourceValue(100),
},
GPU: &atypes.GPU{
Units: atypes.NewResourceValue(0),
},
Memory: &atypes.Memory{
Quantity: atypes.NewResourceValue(128 * unit.Mi),
},
Storage: atypes.Volumes{
{
Name: "default",
Quantity: atypes.NewResourceValue(1 * unit.Gi),
},
{
Name: "configs",
Quantity: atypes.NewResourceValue(1 * unit.Gi),
Attributes: atypes.Attributes{
{
Key: "class",
Value: "default",
},
{
Key: "persistent",
Value: "true",
},
},
},
},
Endpoints: []atypes.Endpoint{
{
Kind: atypes.Endpoint_SHARED_HTTP,
},
{
Kind: atypes.Endpoint_RANDOM_PORT,
},
},
},
Params: &manifest.ServiceParams{
Storage: []manifest.StorageParams{
{
Name: "configs",
Mount: "/test",
ReadOnly: false,
},
},
},
Count: 1,
Expose: []manifest.ServiceExpose{
{
Port: 80, Global: true, Proto: manifest.TCP, Hosts: []string{"ahostname.com"},
HTTPOptions: defaultHTTPOptions,
},
{
Port: 12345, Global: true, Proto: manifest.UDP,
HTTPOptions: defaultHTTPOptions,
},
},
},
},
}, mani.GetGroups()[0])
}

0 comments on commit 6bf4400

Please sign in to comment.