github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/rancher/util_test.go (about)

     1  package rancher
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/rancher/go-rancher/client"
     7  )
     8  
     9  var idTests = []struct {
    10  	id         string
    11  	envID      string
    12  	resourceID string
    13  }{
    14  	{"1a05", "", "1a05"},
    15  	{"1a05/1s234", "1a05", "1s234"},
    16  }
    17  
    18  func TestSplitId(t *testing.T) {
    19  	for _, tt := range idTests {
    20  		envID, resourceID := splitID(tt.id)
    21  		if envID != tt.envID || resourceID != tt.resourceID {
    22  			t.Errorf("splitId(%s) => [%s, %s]) want [%s, %s]", tt.id, envID, resourceID, tt.envID, tt.resourceID)
    23  		}
    24  	}
    25  }
    26  
    27  var stateTests = []struct {
    28  	state   string
    29  	removed bool
    30  }{
    31  	{"removed", true},
    32  	{"purged", true},
    33  	{"active", false},
    34  }
    35  
    36  func TestRemovedState(t *testing.T) {
    37  	for _, tt := range stateTests {
    38  		removed := removed(tt.state)
    39  		if removed != tt.removed {
    40  			t.Errorf("removed(%s) => %t, wants %t", tt.state, removed, tt.removed)
    41  		}
    42  	}
    43  }
    44  
    45  var orchestrationTests = []struct {
    46  	project       *client.Project
    47  	orchestration string
    48  }{
    49  	{&client.Project{}, "cattle"},
    50  	{&client.Project{Swarm: true}, "swarm"},
    51  	{&client.Project{Mesos: true}, "mesos"},
    52  	{&client.Project{Kubernetes: true}, "kubernetes"},
    53  }
    54  
    55  func TestActiveOrchestration(t *testing.T) {
    56  	for _, tt := range orchestrationTests {
    57  		orchestration := getActiveOrchestration(tt.project)
    58  		if orchestration != tt.orchestration {
    59  			t.Errorf("getActiveOrchestration(%+v) => %s, wants %s", tt.project, orchestration, tt.orchestration)
    60  		}
    61  	}
    62  }