package platform

import "testing"

func TestSplitQuotedFields(t *testing.T) {
	t.Parallel()

	line := `NAME="sdb1" TYPE="part" LABEL="BEE EXPORT" MODEL="USB DISK 3.0"`
	got := splitQuotedFields(line)
	want := []string{
		`NAME="sdb1"`,
		`TYPE="part"`,
		`LABEL="BEE EXPORT"`,
		`MODEL="USB DISK 3.0"`,
	}

	if len(got) != len(want) {
		t.Fatalf("len(got)=%d len(want)=%d; got=%q", len(got), len(want), got)
	}
	for i := range want {
		if got[i] != want[i] {
			t.Fatalf("got[%d]=%q want %q", i, got[i], want[i])
		}
	}
}

func TestParseLSBLKPairs(t *testing.T) {
	t.Parallel()

	line := `NAME="sdb1" TYPE="part" PKNAME="sdb" RM="1" FSTYPE="vfat" MOUNTPOINT="" SIZE="57.3G" LABEL="BEE EXPORT" MODEL="USB DISK 3.0"`
	got := parseLSBLKPairs(line)

	checks := map[string]string{
		"NAME":       "sdb1",
		"TYPE":       "part",
		"PKNAME":     "sdb",
		"RM":         "1",
		"FSTYPE":     "vfat",
		"MOUNTPOINT": "",
		"SIZE":       "57.3G",
		"LABEL":      "BEE EXPORT",
		"MODEL":      "USB DISK 3.0",
	}
	for key, want := range checks {
		if got[key] != want {
			t.Fatalf("got[%s]=%q want %q", key, got[key], want)
		}
	}
}
