mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-15 10:51:12 +02:00
That's the recommended syntax: https://golangci-lint.run/usage/false-positives/ Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
98 lines
1.8 KiB
Go
98 lines
1.8 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
//nolint:scopelint
|
|
package runtime_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
|
|
)
|
|
|
|
func TestMode_String(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
m runtime.Mode
|
|
want string
|
|
}{
|
|
{
|
|
name: "cloud",
|
|
m: runtime.ModeCloud,
|
|
want: "cloud",
|
|
},
|
|
{
|
|
name: "container",
|
|
m: runtime.ModeContainer,
|
|
want: "container",
|
|
},
|
|
{
|
|
name: "metal",
|
|
m: runtime.ModeMetal,
|
|
want: "metal",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.m.String(); got != tt.want {
|
|
t.Errorf("Mode.String() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseMode(t *testing.T) {
|
|
type args struct {
|
|
s string
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantM runtime.Mode
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "cloud",
|
|
args: args{"cloud"},
|
|
wantM: runtime.ModeCloud,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "container",
|
|
args: args{"container"},
|
|
wantM: runtime.ModeContainer,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "metal",
|
|
args: args{"metal"},
|
|
wantM: runtime.ModeMetal,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "invalid",
|
|
args: args{"invalid"},
|
|
wantM: 0,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotM, err := runtime.ParseMode(tt.args.s)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ParseMode() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(gotM, tt.wantM) {
|
|
t.Errorf("ParseMode() = %v, want %v", gotM, tt.wantM)
|
|
}
|
|
})
|
|
}
|
|
}
|