123 lines
2.3 KiB
Go
123 lines
2.3 KiB
Go
|
|
package cmd
|
||
|
|
|
||
|
|
import (
|
||
|
|
"reflect"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestSplitKeyValue(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
input string
|
||
|
|
expected []string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "valid key=value",
|
||
|
|
input: "environment=production",
|
||
|
|
expected: []string{"environment", "production"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "key with empty value",
|
||
|
|
input: "key=",
|
||
|
|
expected: []string{"key", ""},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "value with equals sign",
|
||
|
|
input: "url=https://example.com?foo=bar",
|
||
|
|
expected: []string{"url", "https://example.com?foo=bar"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "no equals sign",
|
||
|
|
input: "invalid",
|
||
|
|
expected: []string{"invalid"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "multiple equals signs",
|
||
|
|
input: "a=b=c=d",
|
||
|
|
expected: []string{"a", "b=c=d"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "empty string",
|
||
|
|
input: "",
|
||
|
|
expected: []string{""},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "just equals sign",
|
||
|
|
input: "=",
|
||
|
|
expected: []string{"", ""},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
result := splitKeyValue(tt.input)
|
||
|
|
if !reflect.DeepEqual(result, tt.expected) {
|
||
|
|
t.Errorf("splitKeyValue(%q) = %v, want %v", tt.input, result, tt.expected)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestFormatStatus(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
status string
|
||
|
|
expected string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "success status",
|
||
|
|
status: "success",
|
||
|
|
expected: "✓ success",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "failure status",
|
||
|
|
status: "failure",
|
||
|
|
expected: "✗ failure",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "cancelled status",
|
||
|
|
status: "cancelled",
|
||
|
|
expected: "- cancelled",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "skipped status",
|
||
|
|
status: "skipped",
|
||
|
|
expected: "○ skipped",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "in_progress status",
|
||
|
|
status: "in_progress",
|
||
|
|
expected: "● in progress",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "running status",
|
||
|
|
status: "running",
|
||
|
|
expected: "● in progress",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "queued status",
|
||
|
|
status: "queued",
|
||
|
|
expected: "○ queued",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "waiting status",
|
||
|
|
status: "waiting",
|
||
|
|
expected: "○ queued",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "unknown status",
|
||
|
|
status: "unknown",
|
||
|
|
expected: "unknown",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
result := formatStatus(tt.status)
|
||
|
|
if result != tt.expected {
|
||
|
|
t.Errorf("formatStatus(%q) = %q, want %q", tt.status, result, tt.expected)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|