github.com/devcamcar/cli@v0.0.0-20181107134215-706a05759d18/test/cli_migrate_funcfile_test.go (about)

     1  package test
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/fnproject/cli/commands"
     9  	"github.com/fnproject/cli/testharness"
    10  )
    11  
    12  func TestMigrateFuncYaml(t *testing.T) {
    13  
    14  	for _, rt := range Runtimes {
    15  		t.Run(fmt.Sprintf("%s migrating V1 func file with runtime", rt.runtime), func(t *testing.T) {
    16  			h := testharness.Create(t)
    17  			defer h.Cleanup()
    18  
    19  			appName := h.NewAppName()
    20  			funcName := h.NewFuncName(appName)
    21  			h.MkDir(funcName)
    22  			h.Cd(funcName)
    23  
    24  			h.CreateFuncfile(funcName, rt.runtime)
    25  			h.Fn("migrate").AssertSuccess().AssertStdoutContains(commands.MigrateSuccessMessage)
    26  
    27  			funcYaml := h.GetFile("func.yaml")
    28  			if !strings.Contains(funcYaml, "schema_version") {
    29  				t.Fatalf("Exepected schema_version in %s", funcYaml)
    30  			}
    31  
    32  			yamlFile := h.GetYamlFile("func.yaml")
    33  			if !strings.HasPrefix(yamlFile.Triggers[0].Source, "/") {
    34  				t.Fatalf("Exepected source to have a leading '/' in %s", yamlFile.Triggers[0].Source)
    35  			}
    36  			if yamlFile.Triggers[0].Type != "http" {
    37  				t.Fatalf("Exepected type to be 'http' in %s", yamlFile.Triggers[0].Type)
    38  			}
    39  		})
    40  	}
    41  }
    42  
    43  func TestMigrateFuncYamlV20180708(t *testing.T) {
    44  
    45  	for _, rt := range Runtimes {
    46  		t.Run(fmt.Sprintf("%s migrating runtime", rt.runtime), func(t *testing.T) {
    47  			h := testharness.Create(t)
    48  			defer h.Cleanup()
    49  
    50  			appName := h.NewAppName()
    51  			funcName := h.NewFuncName(appName)
    52  			h.Fn("init", "--runtime", rt.runtime, funcName).AssertSuccess()
    53  			h.Cd(funcName)
    54  			h.Fn("migrate").AssertFailed().AssertStderrContains(commands.MigrateFailureMessage)
    55  			h.Cd("")
    56  		})
    57  	}
    58  }