@@ -1831,6 +1831,50 @@ func TestDeploy_UnsetFlag(t *testing.T) { |
1831 | 1831 | } |
1832 | 1832 | } |
1833 | 1833 |
|
| 1834 | +// TestDeploy_DeployerRemote ensures that when deploying remotely, |
| 1835 | +// func.yaml is written to disk before the pipeline starts, so the on-cluster |
| 1836 | +// deploy step picks up the --deployer value. |
| 1837 | +func TestDeploy_DeployerRemote(t *testing.T) { |
| 1838 | + root := FromTempDirectory(t) |
| 1839 | + |
| 1840 | + f := fn.Function{Runtime: "go", Root: root, Registry: TestRegistry} |
| 1841 | + _, err := fn.New().Init(f) |
| 1842 | + if err != nil { |
| 1843 | + t.Fatal(err) |
| 1844 | + } |
| 1845 | + |
| 1846 | + pipelinesProvider := mock.NewPipelinesProvider() |
| 1847 | + pipelinesProvider.RunFn = func(f fn.Function) (string, fn.Function, error) { |
| 1848 | + // Inside the pipeline Run, func.yaml on disk should already |
| 1849 | + // have the deployer written. |
| 1850 | + diskFn, err := fn.NewFunction(root) |
| 1851 | + if err != nil { |
| 1852 | + t.Fatalf("failed to load func.yaml during pipeline Run: %v", err) |
| 1853 | + } |
| 1854 | + if diskFn.Deploy.Deployer != "keda" { |
| 1855 | + t.Fatalf("expected func.yaml on disk to have deployer 'keda', got '%v'", diskFn.Deploy.Deployer) |
| 1856 | + } |
| 1857 | + f.Deploy.Namespace = "default" |
| 1858 | + if f.Deploy.Image, err = f.ImageName(); err != nil { |
| 1859 | + return "", f, err |
| 1860 | + } |
| 1861 | + return "", f, nil |
| 1862 | + } |
| 1863 | + |
| 1864 | + cmd := NewDeployCmd(NewTestClient( |
| 1865 | + fn.WithPipelinesProvider(pipelinesProvider), |
| 1866 | + fn.WithRegistry(TestRegistry), |
| 1867 | + )) |
| 1868 | + cmd.SetArgs([]string{"--remote", "--deployer=keda", "--namespace=default"}) |
| 1869 | + if err := cmd.Execute(); err != nil { |
| 1870 | + t.Fatal(err) |
| 1871 | + } |
| 1872 | + |
| 1873 | + if !pipelinesProvider.RunInvoked { |
| 1874 | + t.Fatal("expected pipeline Run to be invoked") |
| 1875 | + } |
| 1876 | +} |
| 1877 | + |
1834 | 1878 | // Test_ValidateBuilder tests that the builder validation accepts the |
1835 | 1879 | // set of known builders, and spot-checks an error is thrown for unknown. |
1836 | 1880 | func Test_ValidateBuilder(t *testing.T) { |
|