github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/backend/httpstate/console_test.go (about)

     1  // Copyright 2016-2018, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //	http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package httpstate
    15  
    16  import (
    17  	"os"
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  //nolint:paralleltest // sets env var, must be run in isolation
    24  func TestConsoleURL(t *testing.T) {
    25  
    26  	//nolint:paralleltest // sets env var, must be run in isolation
    27  	t.Run("HonorEnvVar", func(t *testing.T) {
    28  		// Honor the PULUMI_CONSOLE_DOMAIN environment variable.
    29  		t.Setenv("PULUMI_CONSOLE_DOMAIN", "pulumi-console.contoso.com")
    30  		assert.Equal(t,
    31  			"https://pulumi-console.contoso.com/1/2",
    32  			cloudConsoleURL("https://api.pulumi.contoso.com", "1", "2"))
    33  
    34  		// Unset the variable, confirm the "standard behavior" where we
    35  		// replace "api." with "app.".
    36  		os.Unsetenv("PULUMI_CONSOLE_DOMAIN")
    37  		assert.Equal(t,
    38  			"https://app.pulumi.contoso.com/1/2",
    39  			cloudConsoleURL("https://api.pulumi.contoso.com", "1", "2"))
    40  	})
    41  
    42  	t.Run("CloudURLUsingStandardPattern", func(t *testing.T) {
    43  		assert.Equal(t,
    44  			"https://app.pulumi.com/pulumi-bot/my-stack",
    45  			cloudConsoleURL("https://api.pulumi.com", "pulumi-bot", "my-stack"))
    46  
    47  		assert.Equal(t,
    48  			"http://app.pulumi.example.com/pulumi-bot/my-stack",
    49  			cloudConsoleURL("http://api.pulumi.example.com", "pulumi-bot", "my-stack"))
    50  	})
    51  
    52  	t.Run("LocalDevelopment", func(t *testing.T) {
    53  		assert.Equal(t,
    54  			"http://localhost:3000/pulumi-bot/my-stack",
    55  			cloudConsoleURL("http://localhost:8080", "pulumi-bot", "my-stack"))
    56  	})
    57  
    58  	t.Run("ConsoleDomainUnknown", func(t *testing.T) {
    59  		assert.Equal(t, "", cloudConsoleURL("https://pulumi.example.com", "pulumi-bot", "my-stack"))
    60  		assert.Equal(t, "", cloudConsoleURL("not-even-a-real-url", "pulumi-bot", "my-stack"))
    61  	})
    62  }