github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/client/util_test.go (about)

     1  package client
     2  
     3  /*
     4  TODO(clientv2)
     5  import (
     6  	"reflect"
     7  	"testing"
     8  
     9  	"github.com/hashicorp/nomad/helper/uuid"
    10  	"github.com/hashicorp/nomad/nomad/mock"
    11  	"github.com/hashicorp/nomad/nomad/structs"
    12  )
    13  
    14  func TestDiffAllocs(t *testing.T) {
    15  	t.Parallel()
    16  	alloc1 := mock.Alloc() // Ignore
    17  	alloc2 := mock.Alloc() // Update
    18  	alloc2u := new(structs.Allocation)
    19  	*alloc2u = *alloc2
    20  	alloc2u.AllocModifyIndex += 1
    21  	alloc3 := mock.Alloc() // Remove
    22  	alloc4 := mock.Alloc() // Add
    23  
    24  	exist := []*structs.Allocation{
    25  		alloc1,
    26  		alloc2,
    27  		alloc3,
    28  	}
    29  	update := &allocUpdates{
    30  		pulled: map[string]*structs.Allocation{
    31  			alloc2u.ID: alloc2u,
    32  			alloc4.ID:  alloc4,
    33  		},
    34  		filtered: map[string]struct{}{
    35  			alloc1.ID: {},
    36  		},
    37  	}
    38  
    39  	result := diffAllocs(exist, update)
    40  
    41  	if len(result.ignore) != 1 || result.ignore[0] != alloc1 {
    42  		t.Fatalf("Bad: %#v", result.ignore)
    43  	}
    44  	if len(result.added) != 1 || result.added[0] != alloc4 {
    45  		t.Fatalf("Bad: %#v", result.added)
    46  	}
    47  	if len(result.removed) != 1 || result.removed[0] != alloc3 {
    48  		t.Fatalf("Bad: %#v", result.removed)
    49  	}
    50  	if len(result.updated) != 1 {
    51  		t.Fatalf("Bad: %#v", result.updated)
    52  	}
    53  	if result.updated[0].exist != alloc2 || result.updated[0].updated != alloc2u {
    54  		t.Fatalf("Bad: %#v", result.updated)
    55  	}
    56  }
    57  
    58  func TestShuffleStrings(t *testing.T) {
    59  	t.Parallel()
    60  	// Generate input
    61  	inp := make([]string, 10)
    62  	for idx := range inp {
    63  		inp[idx] = uuid.Generate()
    64  	}
    65  
    66  	// Copy the input
    67  	orig := make([]string, len(inp))
    68  	copy(orig, inp)
    69  
    70  	// Shuffle
    71  	shuffleStrings(inp)
    72  
    73  	// Ensure order is not the same
    74  	if reflect.DeepEqual(inp, orig) {
    75  		t.Fatalf("shuffle failed")
    76  	}
    77  }
    78  */