package common

import "testing"

func TestParseOperatorEntity(t *testing.T) {
	operatorEntity := BuildOperatorEntity("api_key", "key-a")
	if operatorEntity != "api_key:key-a" {
		t.Fatalf("operator entity = %q, want %q", operatorEntity, "api_key:key-a")
	}

	operatorType, operatorName, ok := ParseOperatorEntity(operatorEntity)
	if !ok {
		t.Fatalf("ok = false, want true")
	}
	if operatorType != "api_key" {
		t.Fatalf("operator type = %q, want %q", operatorType, "api_key")
	}
	if operatorName != "key-a" {
		t.Fatalf("operator name = %q, want %q", operatorName, "key-a")
	}

	_, _, ok = ParseOperatorEntity("invalid")
	if ok {
		t.Fatalf("ok = true, want false")
	}
}
