github.com/tmlbl/deis@v1.0.2/tests/integration_test.go (about)

     1  // +build integration
     2  
     3  package tests
     4  
     5  import (
     6  	"encoding/json"
     7  	"io/ioutil"
     8  	"os/user"
     9  	"path"
    10  	"testing"
    11  
    12  	"github.com/deis/deis/tests/utils"
    13  )
    14  
    15  const clientJsonFilePath string = ".deis/client.json"
    16  
    17  var (
    18  	gitCloneCmd  = "if [ ! -d {{.ExampleApp}} ] ; then git clone https://github.com/deis/{{.ExampleApp}}.git ; fi"
    19  	gitRemoveCmd = "git remote remove deis"
    20  	gitPushCmd   = "git push deis master"
    21  )
    22  
    23  // Client represents the client data structure in ~/.deis/client.json
    24  type Client struct {
    25  	Controller string `json:"controller"`
    26  	Username   string `json:"username"`
    27  	Token      string `json:"token"`
    28  }
    29  
    30  func TestGlobal(t *testing.T) {
    31  	params := utils.GetGlobalConfig()
    32  	utils.Execute(t, authRegisterCmd, params, false, "")
    33  	clientTest(t, params)
    34  	utils.Execute(t, keysAddCmd, params, false, "")
    35  }
    36  
    37  func clientTest(t *testing.T, params *utils.DeisTestConfig) {
    38  	user, err := user.Current()
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	data, err := ioutil.ReadFile(path.Join(user.HomeDir, clientJsonFilePath))
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  	client := &Client{}
    47  	json.Unmarshal(data, &client)
    48  	if client.Token == "" {
    49  		t.Error("token not present in client.json")
    50  	}
    51  	if client.Controller == "" {
    52  		t.Error("controller endpoint not present in client.json")
    53  	}
    54  	if client.Username == "" {
    55  		t.Error("username not present in client.json")
    56  	}
    57  }