mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
ffc931aad1
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files. * Added unit build tag to all unit test files. * added to new unit test unit build tag * Update verify-go.yml * small fix --------- Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
159 lines
3.0 KiB
Go
159 lines
3.0 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package multiarch
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPlatformToString(t *testing.T) {
|
|
tt := []struct {
|
|
uut Platform
|
|
expect string
|
|
}{
|
|
{
|
|
uut: Platform{
|
|
OS: "linux",
|
|
Arch: "arm64",
|
|
},
|
|
expect: "linux/arm64",
|
|
},
|
|
{
|
|
uut: Platform{
|
|
OS: "linux",
|
|
Arch: "arm64",
|
|
Variant: "v8",
|
|
},
|
|
expect: "linux/arm64/v8",
|
|
},
|
|
}
|
|
|
|
for _, test := range tt {
|
|
t.Run(test.expect, func(t *testing.T) {
|
|
assert.Equal(t, test.expect, test.uut.ToString())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParsePlatformString(t *testing.T) {
|
|
tt := []struct {
|
|
description string
|
|
input string
|
|
expect Platform
|
|
expectError string
|
|
}{
|
|
{
|
|
description: "format used by golangBuild - only os + arch",
|
|
input: "linux,amd64",
|
|
expect: Platform{
|
|
OS: "linux",
|
|
Arch: "amd64",
|
|
},
|
|
},
|
|
{
|
|
description: "format used by kanikoExecute - os/arch/variant",
|
|
input: "linux/amd64/v8",
|
|
expect: Platform{
|
|
OS: "linux",
|
|
Arch: "amd64",
|
|
Variant: "v8",
|
|
},
|
|
},
|
|
{
|
|
description: "sth in between - os,arch,variant",
|
|
input: "linux,amd64,v8",
|
|
expect: Platform{
|
|
OS: "linux",
|
|
Arch: "amd64",
|
|
Variant: "v8",
|
|
},
|
|
},
|
|
{
|
|
description: "should be case insensitive",
|
|
input: "LINUX/AMD64/V8",
|
|
expect: Platform{
|
|
OS: "linux",
|
|
Arch: "amd64",
|
|
Variant: "v8",
|
|
},
|
|
},
|
|
{
|
|
description: "whitespaces shall be trimmed",
|
|
input: " linux/ amd64 / v8",
|
|
expect: Platform{
|
|
OS: "linux",
|
|
Arch: "amd64",
|
|
Variant: "v8",
|
|
},
|
|
},
|
|
{
|
|
description: "reads unsupported values",
|
|
input: "myfancyos/runningonafancyarchitecture",
|
|
expect: Platform{
|
|
OS: "myfancyos",
|
|
Arch: "runningonafancyarchitecture",
|
|
},
|
|
},
|
|
{
|
|
description: "os + arch are required, variant is optional",
|
|
input: "linux",
|
|
expectError: "unable to parse platform 'linux'",
|
|
},
|
|
}
|
|
|
|
for _, test := range tt {
|
|
t.Run(test.description, func(t *testing.T) {
|
|
p, err := ParsePlatformString(test.input)
|
|
|
|
if len(test.expectError) > 0 {
|
|
assert.EqualError(t, err, test.expectError)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
assert.Equal(t, test.expect, p)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParsePlatformStringStrings(t *testing.T) {
|
|
tt := []struct {
|
|
description string
|
|
inputs []string
|
|
expect []Platform
|
|
expectError string
|
|
}{
|
|
{
|
|
description: "format used by golangBuild - only os + arch",
|
|
inputs: []string{"linux,amd64", "windows,amd64"},
|
|
expect: []Platform{
|
|
Platform{
|
|
OS: "linux",
|
|
Arch: "amd64",
|
|
},
|
|
Platform{
|
|
OS: "windows",
|
|
Arch: "amd64",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tt {
|
|
t.Run(test.description, func(t *testing.T) {
|
|
p, err := ParsePlatformStrings(test.inputs)
|
|
|
|
if len(test.expectError) > 0 {
|
|
assert.EqualError(t, err, test.expectError)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
assert.Equal(t, test.expect, p)
|
|
})
|
|
}
|
|
}
|