@@ -323,6 +323,13 @@ func TestMinimal_v1_34(t *testing.T) {
323323 runTestTerraformAWS (t )
324324}
325325
326+ // TestMinimalAzure runs the test on a minimum Azure configuration.
327+ func TestMinimalAzure (t * testing.T ) {
328+ newIntegrationTest ("minimal-azure.example.com" , "minimal_azure" ).
329+ withVersion ("v1alpha3" ).
330+ runTestTerraformAzure (t )
331+ }
332+
326333// TestMinimal_NoneDNS runs the test on a minimum configuration with --dns=none
327334func TestMinimal_NoneDNS (t * testing.T ) {
328335 newIntegrationTest ("minimal.example.com" , "minimal-dns-none" ).
@@ -1736,6 +1743,111 @@ func (i *integrationTest) runTestTerraformGCE(t *testing.T) {
17361743 i .runTest (t , ctx , h , expectedFilenames , "" , "" , nil )
17371744}
17381745
1746+ func (i * integrationTest ) runTestTerraformAzure (t * testing.T ) {
1747+ t .Setenv ("AZURE_STORAGE_ACCOUNT" , "teststorage" )
1748+ t .Setenv ("KOPS_RUN_TOO_NEW_VERSION" , "1" )
1749+
1750+ featureflag .ParseFlags ("+Azure,+AzureTerraform" )
1751+ defer featureflag .ParseFlags ("-Azure,-AzureTerraform" )
1752+
1753+ ctx := testcontext .ForTest (t )
1754+ h := testutils .NewIntegrationTestHarness (t )
1755+ defer h .Close ()
1756+
1757+ h .MockKopsVersion ("1.34.0-beta.1" )
1758+ h .SetupMockAzure ()
1759+
1760+ var stdout bytes.Buffer
1761+
1762+ i .srcDir = updateClusterTestBase + i .srcDir
1763+ inputYAML := "in-" + i .version + ".yaml"
1764+
1765+ factory := i .setupCluster (t , ctx , inputYAML , stdout )
1766+
1767+ options := & UpdateClusterOptions {}
1768+ options .InitDefaults ()
1769+ options .Target = "terraform"
1770+ options .OutDir = path .Join (h .TempDir , "out" )
1771+ options .RunTasksOptions .MaxTaskDuration = 30 * time .Second
1772+ options .CreateKubecfg = false
1773+ options .ClusterName = i .clusterName
1774+
1775+ updateClusterResults , err := RunUpdateCluster (ctx , factory , & stdout , options )
1776+ if err != nil {
1777+ t .Fatalf ("error running update cluster %q: %v" , i .clusterName , err )
1778+ }
1779+
1780+ for key , task := range updateClusterResults .TaskMap {
1781+ if _ , err := json .Marshal (task ); err != nil {
1782+ t .Errorf ("unable to marshal task %q of type %T to json: %v" , key , task , err )
1783+ }
1784+ }
1785+
1786+ files , err := os .ReadDir (path .Join (h .TempDir , "out" ))
1787+ if err != nil {
1788+ t .Fatalf ("failed to read dir: %v" , err )
1789+ }
1790+
1791+ var fileNames []string
1792+ for _ , f := range files {
1793+ fileNames = append (fileNames , f .Name ())
1794+ }
1795+ sort .Strings (fileNames )
1796+ if actual , expected := strings .Join (fileNames , "," ), "data,kubernetes.tf" ; actual != expected {
1797+ t .Fatalf ("unexpected files. actual=%q, expected=%q, test=%q" , actual , expected , "kubernetes.tf" )
1798+ }
1799+
1800+ actualTF , err := os .ReadFile (path .Join (h .TempDir , "out" , "kubernetes.tf" ))
1801+ if err != nil {
1802+ t .Fatalf ("unexpected error reading actual terraform output: %v" , err )
1803+ }
1804+ golden .AssertMatchesFile (t , string (actualTF ), path .Join (i .srcDir , "kubernetes.tf" ))
1805+
1806+ actualDataDir := filepath .Join (h .TempDir , "out" , "data" )
1807+ actualDataFiles , err := os .ReadDir (actualDataDir )
1808+ if err != nil {
1809+ t .Fatalf ("failed to read data dir %q: %v" , actualDataDir , err )
1810+ }
1811+
1812+ var actualDataFilenames []string
1813+ for _ , f := range actualDataFiles {
1814+ actualDataFilenames = append (actualDataFilenames , f .Name ())
1815+ }
1816+ sort .Strings (actualDataFilenames )
1817+
1818+ expectedDataDir := filepath .Join (i .srcDir , "data" )
1819+ expectedDataFilenames := actualDataFilenames
1820+ if ! golden .UpdateExpectedOutput () {
1821+ expectedDataFiles , err := os .ReadDir (expectedDataDir )
1822+ if err != nil {
1823+ t .Fatalf ("failed to read data dir %q: %v" , expectedDataDir , err )
1824+ }
1825+ expectedDataFilenames = make ([]string , 0 , len (expectedDataFiles ))
1826+ for _ , f := range expectedDataFiles {
1827+ expectedDataFilenames = append (expectedDataFilenames , f .Name ())
1828+ }
1829+ sort .Strings (expectedDataFilenames )
1830+ }
1831+
1832+ for _ , filename := range expectedDataFilenames {
1833+ expectedPath := filepath .Join (expectedDataDir , filename )
1834+ actualPath := filepath .Join (actualDataDir , filename )
1835+ actualDataContent , err := os .ReadFile (actualPath )
1836+ if err != nil {
1837+ t .Errorf ("failed to read actual data file %q: %v" , actualPath , err )
1838+ continue
1839+ }
1840+ golden .AssertMatchesFile (t , string (actualDataContent ), expectedPath )
1841+ }
1842+
1843+ if ! reflect .DeepEqual (actualDataFilenames , expectedDataFilenames ) {
1844+ actual := strings .Join (actualDataFilenames , "\n " )
1845+ expected := strings .Join (expectedDataFilenames , "\n " )
1846+ t .Log (diff .FormatDiff (actual , expected ))
1847+ t .Error ("unexpected data files." )
1848+ }
1849+ }
1850+
17391851func (i * integrationTest ) runTestTerraformHetzner (t * testing.T ) {
17401852 t .Setenv ("KOPS_RUN_TOO_NEW_VERSION" , "1" )
17411853
0 commit comments