| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | package setting | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 17:23:13 +08:00
										 |  |  | 	"github.com/grafana/grafana-azure-sdk-go/azsettings" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | 	"github.com/stretchr/testify/assert" | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/require" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestAzureSettings(t *testing.T) { | 
					
						
							|  |  |  | 	t.Run("cloud name", func(t *testing.T) { | 
					
						
							|  |  |  | 		testCases := []struct { | 
					
						
							|  |  |  | 			name            string | 
					
						
							|  |  |  | 			configuredValue string | 
					
						
							|  |  |  | 			resolvedValue   string | 
					
						
							|  |  |  | 		}{ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name:            "should be Public if not set", | 
					
						
							|  |  |  | 				configuredValue: "", | 
					
						
							| 
									
										
										
										
											2022-04-01 19:26:49 +08:00
										 |  |  | 				resolvedValue:   azsettings.AzurePublic, | 
					
						
							| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name:            "should be Public if set to Public", | 
					
						
							| 
									
										
										
										
											2022-04-01 19:26:49 +08:00
										 |  |  | 				configuredValue: azsettings.AzurePublic, | 
					
						
							|  |  |  | 				resolvedValue:   azsettings.AzurePublic, | 
					
						
							| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name:            "should be Public if set to Public using alternative name", | 
					
						
							|  |  |  | 				configuredValue: "AzurePublicCloud", | 
					
						
							| 
									
										
										
										
											2022-04-01 19:26:49 +08:00
										 |  |  | 				resolvedValue:   azsettings.AzurePublic, | 
					
						
							| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name:            "should be China if set to China", | 
					
						
							| 
									
										
										
										
											2022-04-01 19:26:49 +08:00
										 |  |  | 				configuredValue: azsettings.AzureChina, | 
					
						
							|  |  |  | 				resolvedValue:   azsettings.AzureChina, | 
					
						
							| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name:            "should be US Government if set to US Government using alternative name", | 
					
						
							|  |  |  | 				configuredValue: "usgov", | 
					
						
							| 
									
										
										
										
											2022-04-01 19:26:49 +08:00
										 |  |  | 				resolvedValue:   azsettings.AzureUSGovernment, | 
					
						
							| 
									
										
										
										
											2021-08-13 21:58:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name:            "should be same as set if not known", | 
					
						
							|  |  |  | 				configuredValue: "Custom123", | 
					
						
							|  |  |  | 				resolvedValue:   "Custom123", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for _, c := range testCases { | 
					
						
							|  |  |  | 			t.Run(c.name, func(t *testing.T) { | 
					
						
							|  |  |  | 				cfg := NewCfg() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				azureSection, err := cfg.Raw.NewSection("azure") | 
					
						
							|  |  |  | 				require.NoError(t, err) | 
					
						
							|  |  |  | 				_, err = azureSection.NewKey("cloud", c.configuredValue) | 
					
						
							|  |  |  | 				require.NoError(t, err) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				cfg.readAzureSettings() | 
					
						
							|  |  |  | 				require.NotNil(t, cfg.Azure) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				assert.Equal(t, c.resolvedValue, cfg.Azure.Cloud) | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } |