package utils

import "testing"

func TestParseSortByFiled(t *testing.T) {
	result := ParseSortByFiled("creationTimestamp   desc,    name    asc")
	if len(result) != 2 {
		t.Fatal("parse failed")
	}
	if result[0].Field != "creationTimestamp" {
		t.Fatal("parse failed")
	}
	if result[1].Desc {
		t.Fatal("parse failed")
	}
	ParseSortByFiled("")
}

func TestMakeNilSlice2EmptySlice(t *testing.T) {
	var s []string
	r := MakeNilSlice2EmptySlice(s)
	if r.([]string) == nil {
		t.Fatal("must not be nil")
	}

	t2 := []string{"abc"}
	tr2 := MakeNilSlice2EmptySlice(t2)
	if tr2.([]string) == nil {
		t.Fatal("must not be nil")
	}
	if len(tr2.([]string)) != 1 {
		t.Fatal("invalid size")
	}

	t3 := []string{}
	tr3 := MakeNilSlice2EmptySlice(t3)
	if tr3.([]string) == nil {
		t.Fatal("must not be nil")
	}
	if len(tr3.([]string)) != 0 {
		t.Fatal("invalid size")
	}
}
