Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ func (i *Input) newPlatforms() map[string]string {
}

for _, p := range i.platforms {
pParts := strings.Split(p, "=")
if len(pParts) == 2 {
platforms[strings.ToLower(pParts[0])] = pParts[1]
idx := strings.LastIndex(p, "=")
if idx != -1 {
platforms[strings.ToLower(p[:idx])] = p[idx+1:]
}
}
return platforms
Expand Down
81 changes: 81 additions & 0 deletions cmd/platforms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewPlatforms(t *testing.T) {
tests := []struct {
name string
platforms []string
expected map[string]string
}{
{
name: "default platforms",
platforms: []string{},
expected: map[string]string{
"ubuntu-latest": "node:16-buster-slim",
"ubuntu-22.04": "node:16-bullseye-slim",
"ubuntu-20.04": "node:16-buster-slim",
"ubuntu-18.04": "node:16-buster-slim",
},
},
{
name: "simple platform override",
platforms: []string{"ubuntu-latest=custom:image"},
expected: map[string]string{
"ubuntu-latest": "custom:image",
"ubuntu-22.04": "node:16-bullseye-slim",
"ubuntu-20.04": "node:16-buster-slim",
"ubuntu-18.04": "node:16-buster-slim",
},
},
{
name: "platform with multiple equals signs",
platforms: []string{"runner=fast-disk-network=catthehacker/ubuntu:act-22.04"},
expected: map[string]string{
"ubuntu-latest": "node:16-buster-slim",
"ubuntu-22.04": "node:16-bullseye-slim",
"ubuntu-20.04": "node:16-buster-slim",
"ubuntu-18.04": "node:16-buster-slim",
"runner=fast-disk-network": "catthehacker/ubuntu:act-22.04",
},
},
{
name: "multiple platform overrides",
platforms: []string{
"ubuntu-latest=custom:image",
"runner=fast-disk-network=catthehacker/ubuntu:act-22.04",
},
expected: map[string]string{
"ubuntu-latest": "custom:image",
"ubuntu-22.04": "node:16-bullseye-slim",
"ubuntu-20.04": "node:16-buster-slim",
"ubuntu-18.04": "node:16-buster-slim",
"runner=fast-disk-network": "catthehacker/ubuntu:act-22.04",
},
},
{
name: "case insensitive platform key",
platforms: []string{"UBUNTU-LATEST=custom:image"},
expected: map[string]string{
"ubuntu-latest": "custom:image",
"ubuntu-22.04": "node:16-bullseye-slim",
"ubuntu-20.04": "node:16-buster-slim",
"ubuntu-18.04": "node:16-buster-slim",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
input := &Input{
platforms: tt.platforms,
}
result := input.newPlatforms()
assert.Equal(t, tt.expected, result)
})
}
}
Loading