github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/plugin/api_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/liamawhite/cli-with-i18n/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("plugin API", func() {
    14  	BeforeEach(func() {
    15  		installTestPlugin()
    16  	})
    17  
    18  	AfterEach(func() {
    19  		uninstallTestPlugin()
    20  	})
    21  
    22  	Describe("AccessToken", func() {
    23  		It("returns the access token", func() {
    24  			confirmTestPluginOutput("AccessToken", "bearer [\\w\\d\\.]+")
    25  		})
    26  	})
    27  
    28  	Describe("ApiEndpoint", func() {
    29  		It("returns the API endpoint", func() {
    30  			confirmTestPluginOutput("ApiEndpoint", apiURL)
    31  		})
    32  	})
    33  
    34  	Describe("ApiVersion", func() {
    35  		It("returns the API version", func() {
    36  			confirmTestPluginOutput("ApiVersion", "2\\.\\d+\\.\\d+")
    37  		})
    38  	})
    39  
    40  	Describe("CliCommand", func() {
    41  		It("calls the core cli command and outputs to terminal", func() {
    42  			confirmTestPluginOutput("CliCommand", "API endpoint", "API endpoint")
    43  		})
    44  	})
    45  
    46  	Describe("CliCommandWithoutTerminalOutput", func() {
    47  		It("calls the core cli command and without outputting to the terminal", func() {
    48  			session := helpers.CF("CliCommandWithoutTerminalOutput", "target")
    49  			Eventually(session).Should(Say("API endpoint"))
    50  			Consistently(session).ShouldNot(Say("API endpoint"))
    51  			Eventually(session).Should(Exit(0))
    52  		})
    53  	})
    54  
    55  	Describe("DopplerEndpoint", func() {
    56  		It("gets Doppler Endpoint", func() {
    57  			confirmTestPluginOutput("DopplerEndpoint", "wss://doppler")
    58  		})
    59  	})
    60  
    61  	Describe("GetApp", func() {
    62  		var appName string
    63  		BeforeEach(func() {
    64  			createTargetedOrgAndSpace()
    65  			appName = helpers.PrefixedRandomName("APP")
    66  			helpers.WithHelloWorldApp(func(appDir string) {
    67  				Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
    68  			})
    69  		})
    70  
    71  		It("gets application information", func() {
    72  			confirmTestPluginOutputWithArg("GetApp", appName, appName)
    73  		})
    74  	})
    75  
    76  	Describe("GetApps", func() {
    77  		var appName1, appName2 string
    78  		BeforeEach(func() {
    79  			createTargetedOrgAndSpace()
    80  			appName1 = helpers.PrefixedRandomName("APP")
    81  			helpers.WithHelloWorldApp(func(appDir string) {
    82  				Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
    83  			})
    84  			appName2 = helpers.PrefixedRandomName("APP")
    85  			helpers.WithHelloWorldApp(func(appDir string) {
    86  				Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
    87  			})
    88  		})
    89  
    90  		It("gets information for multiple applications", func() {
    91  			appNameRegexp := fmt.Sprintf("(?:%s|%s)", appName1, appName2)
    92  			confirmTestPluginOutput("GetApps", appNameRegexp, appNameRegexp)
    93  		})
    94  	})
    95  
    96  	Describe("GetCurrentOrg", func() {
    97  		It("gets the current targeted org", func() {
    98  			org, _ := createTargetedOrgAndSpace()
    99  			confirmTestPluginOutput("GetCurrentOrg", org)
   100  		})
   101  	})
   102  
   103  	Describe("GetCurrentSpace", func() {
   104  		It("gets the current targeted Space", func() {
   105  			_, space := createTargetedOrgAndSpace()
   106  			confirmTestPluginOutput("GetCurrentSpace", space)
   107  		})
   108  	})
   109  
   110  	Describe("GetOrg", func() {
   111  		It("gets the given org", func() {
   112  			org, _ := createTargetedOrgAndSpace()
   113  			confirmTestPluginOutputWithArg("GetOrg", org, org)
   114  		})
   115  	})
   116  
   117  	Describe("GetOrgs", func() {
   118  		It("gets information for multiple orgs", func() {
   119  			org1, _ := createTargetedOrgAndSpace()
   120  			org2, _ := createTargetedOrgAndSpace()
   121  			orgNameRegexp := fmt.Sprintf("(?:%s|%s)", org1, org2)
   122  			confirmTestPluginOutput("GetOrgs", orgNameRegexp, orgNameRegexp)
   123  		})
   124  	})
   125  
   126  	Describe("GetOrgUsers", func() {
   127  		It("returns the org users", func() {
   128  			org, _ := createTargetedOrgAndSpace()
   129  			username, _ := helpers.GetCredentials()
   130  			confirmTestPluginOutputWithArg("GetOrgUsers", org, username)
   131  		})
   132  	})
   133  
   134  	Describe("GetOrgUsers", func() {
   135  		It("returns the org users", func() {
   136  			org, _ := createTargetedOrgAndSpace()
   137  			username, _ := helpers.GetCredentials()
   138  			confirmTestPluginOutputWithArg("GetOrgUsers", org, username)
   139  		})
   140  	})
   141  
   142  	Describe("GetService and GetServices", func() {
   143  		var (
   144  			serviceInstance1 string
   145  			serviceInstance2 string
   146  			broker           helpers.ServiceBroker
   147  		)
   148  		BeforeEach(func() {
   149  			createTargetedOrgAndSpace()
   150  			domain := defaultSharedDomain()
   151  			service := helpers.PrefixedRandomName("SERVICE")
   152  			servicePlan := helpers.PrefixedRandomName("SERVICE-PLAN")
   153  			serviceInstance1 = helpers.PrefixedRandomName("SI1")
   154  			serviceInstance2 = helpers.PrefixedRandomName("SI2")
   155  			broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan)
   156  			broker.Push()
   157  			broker.Configure()
   158  			broker.Create()
   159  
   160  			Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
   161  			Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance1)).Should(Exit(0))
   162  			Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance2)).Should(Exit(0))
   163  		})
   164  
   165  		AfterEach(func() {
   166  			broker.Destroy()
   167  		})
   168  
   169  		It("GetService gets the given service instance and GetServices returns a list of services instances", func() {
   170  			confirmTestPluginOutputWithArg("GetService", serviceInstance1, serviceInstance1)
   171  
   172  			servicesNameRegexp := fmt.Sprintf("(?:%s|%s)", serviceInstance1, serviceInstance2)
   173  			confirmTestPluginOutput("GetServices", servicesNameRegexp, servicesNameRegexp)
   174  		})
   175  	})
   176  
   177  	Describe("GetSpace", func() {
   178  		It("gets the given space", func() {
   179  			_, space := createTargetedOrgAndSpace()
   180  			confirmTestPluginOutputWithArg("GetSpace", space, space)
   181  		})
   182  	})
   183  
   184  	Describe("GetSpaces", func() {
   185  		var space1, space2 string
   186  
   187  		BeforeEach(func() {
   188  			_, space1 = createTargetedOrgAndSpace()
   189  			space2 = helpers.NewSpaceName()
   190  			helpers.CreateSpace(space2)
   191  		})
   192  
   193  		It("gets information for multiple spaces", func() {
   194  			spaceNameRegexp := fmt.Sprintf("(?:%s|%s)", space1, space2)
   195  			confirmTestPluginOutput("GetSpaces", spaceNameRegexp, spaceNameRegexp)
   196  		})
   197  	})
   198  
   199  	Describe("GetSpaceUsers", func() {
   200  		It("returns the space users", func() {
   201  			org, space := createTargetedOrgAndSpace()
   202  			username, _ := helpers.GetCredentials()
   203  			session := helpers.CF("GetSpaceUsers", org, space)
   204  			Eventually(session).Should(Say(username))
   205  			Eventually(session).Should(Exit(0))
   206  		})
   207  	})
   208  
   209  	Describe("HasAPIEndpoint", func() {
   210  		It("returns true", func() {
   211  			confirmTestPluginOutput("HasAPIEndpoint", "true")
   212  		})
   213  	})
   214  
   215  	Describe("HasOrganization", func() {
   216  		It("returns true", func() {
   217  			createTargetedOrgAndSpace()
   218  			confirmTestPluginOutput("HasOrganization", "true")
   219  		})
   220  	})
   221  
   222  	Describe("HasSpace", func() {
   223  		It("returns true", func() {
   224  			createTargetedOrgAndSpace()
   225  			confirmTestPluginOutput("HasSpace", "true")
   226  		})
   227  	})
   228  
   229  	Describe("IsLoggedIn", func() {
   230  		It("returns a true", func() {
   231  			confirmTestPluginOutput("IsLoggedIn", "true")
   232  		})
   233  	})
   234  
   235  	Describe("IsSSLDisabled", func() {
   236  		It("returns a true or false", func() {
   237  			if skipSSLValidation == "" {
   238  				confirmTestPluginOutput("IsSSLDisabled", "false")
   239  			} else {
   240  				confirmTestPluginOutput("IsSSLDisabled", "true")
   241  			}
   242  		})
   243  	})
   244  
   245  	Describe("LoggregatorEndpoint", func() {
   246  		It("gets Loggregator Endpoint", func() {
   247  			confirmTestPluginOutput("LoggregatorEndpoint", "")
   248  		})
   249  	})
   250  
   251  	Describe("UserEmail", func() {
   252  		It("gets the current user's Email", func() {
   253  			username, _ := helpers.GetCredentials()
   254  			confirmTestPluginOutput("UserEmail", username)
   255  		})
   256  	})
   257  
   258  	Describe("UserGuid", func() {
   259  		It("gets the current user's GUID", func() {
   260  			confirmTestPluginOutput("UserGuid", "[\\w\\d]+-[\\w\\d]+-[\\w\\d]+-[\\w\\d]+-[\\w\\d]+")
   261  		})
   262  	})
   263  
   264  	Describe("Username", func() {
   265  		It("gets the current username", func() {
   266  			username, _ := helpers.GetCredentials()
   267  			confirmTestPluginOutput("Username", username)
   268  		})
   269  	})
   270  })