github.com/emicklei/gmig@v1.18.3-0.20240405210147-57c940a1c6cf/gcloud_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestGcloudConfigSetProject(t *testing.T) {
     9  	cc := new(commandCapturer)
    10  	old := runCommand
    11  	runCommand = cc.runCommand
    12  	defer func() { runCommand = old }()
    13  	cfg := Config{Project: "p", Region: "r", Zone: "z"}
    14  	if err := gcloudConfigSetProject(cfg); err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	if got, want := len(cc.args), 3; got != want {
    18  		t.Errorf("got [%v] want [%v]", got, want)
    19  	}
    20  	if got, want := fmt.Sprint(cc.args[0]), "[gcloud config set core/project p]"; got != want {
    21  		t.Errorf("got [%v] want [%v]", got, want)
    22  	}
    23  	if got, want := fmt.Sprint(cc.args[1]), "[gcloud config set compute/region r]"; got != want {
    24  		t.Errorf("got [%v] want [%v]", got, want)
    25  	}
    26  	if got, want := fmt.Sprint(cc.args[2]), "[gcloud config set compute/zone z]"; got != want {
    27  		t.Errorf("got [%v] want [%v]", got, want)
    28  	}
    29  }