You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.0 KiB

  1. package super_block
  2. import (
  3. "testing"
  4. )
  5. func TestReplicaPlacementSerialDeserial(t *testing.T) {
  6. rp, _ := NewReplicaPlacementFromString("001")
  7. newRp, _ := NewReplicaPlacementFromByte(rp.Byte())
  8. if rp.String() != newRp.String() {
  9. println("expected:", rp.String(), "actual:", newRp.String())
  10. t.Fail()
  11. }
  12. }
  13. func TestReplicaPlacementHasReplication(t *testing.T) {
  14. testCases := []struct {
  15. name string
  16. replicaPlacement string
  17. want bool
  18. }{
  19. {"empty replica placement", "", false},
  20. {"no replication", "000", false},
  21. {"same rack replication", "100", true},
  22. {"diff rack replication", "020", true},
  23. {"DC replication", "003", true},
  24. {"full replication", "155", true},
  25. }
  26. for _, tc := range testCases {
  27. t.Run(tc.name, func(t *testing.T) {
  28. rp, err := NewReplicaPlacementFromString(tc.replicaPlacement)
  29. if err != nil {
  30. t.Errorf("failed to initialize ReplicaPlacement: %v", err)
  31. return
  32. }
  33. if got, want := rp.HasReplication(), tc.want; got != want {
  34. t.Errorf("expected %v, got %v", want, got)
  35. }
  36. })
  37. }
  38. }