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 <[email protected]>
  • Loading branch information
troian committed Sep 14, 2023
1 parent 365302a commit f4159f2
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdl/_testdata/storageClass1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
params:
storage:
configs:
mount: /test
profiles:
compute:
web:
Expand Down
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/storageClass1.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 f4159f2

Please sign in to comment.