GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — func/cmd/build_test.go at main · stackbuilders/func Expand file tree/ Copy pathbuild_test.goMore file actions 154 lines (130 loc) · 4.79 KB / Copy pathbuild_test.goFile metadata and controls154 lines (130 loc) · 4.79 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 package cmd import ( "errors" "testing" fn "knative.dev/func/pkg/functions" "knative.dev/func/pkg/mock" . "knative.dev/func/pkg/testing" ) // TestBuild_BuilderPersists ensures that the builder chosen is read from // the function by default, and is able to be overridden by flags/env vars. func TestBuild_BuilderPersists(t *testing.T) { testBuilderPersists(NewBuildCmd, t) } // TestBuild_ValidateBuilder ensures that the validation function correctly // identifies valid and invalid builder short names. func TestBuild_BuilderValidated(t *testing.T) { testBuilderValidated(NewBuildCmd, t) } // TestBuild_ConfigApplied ensures that the build command applies config // settings at each level (static, global, function, envs, flags). func TestBuild_ConfigApplied(t *testing.T) { testConfigApplied(NewBuildCmd, t) } // TestBuild_ConfigPrecedence ensures that the correct precedence for config // are applied: static < global < function context < envs < flags func TestBuild_ConfigPrecedence(t *testing.T) { testConfigPrecedence(NewBuildCmd, t) } // TestBuild_Default ensures that running build on a valid default Function // (only required options populated; all else default) completes successfully. func TestBuild_Default(t *testing.T) { testDefault(NewBuildCmd, t) } // TestBuild_FunctionContext ensures that the function contextually relevant // to the current command execution is loaded and used for flag defaults by // spot-checking the builder setting. func TestBuild_FunctionContext(t *testing.T) { testFunctionContext(NewBuildCmd, t) } // TestBuild_ImageFlag ensures that the image flag is used when specified. func TestBuild_ImageFlag(t *testing.T) { testImageFlag(NewBuildCmd, t) } // TestBuild_ImageAndRegistry ensures that image is derived when --registry // is provided without --image; that --image is used if provided; that when // both are provided, they are both passed to the builder; and that these // values are persisted. func TestBuild_ImageAndRegistry(t *testing.T) { testImageAndRegistry(NewBuildCmd, t) } // TestBuild_InvalidRegistry ensures that providing an invalid registry // fails with the expected error. func TestBuild_InvalidRegistry(t *testing.T) { testInvalidRegistry(NewBuildCmd, t) } // TestBuild_Registry ensures that a function's registry member is kept in // sync with the image tag. // During normal operation (using the client API) a function's state on disk // will be in a valid state, but it is possible that a function could be // manually edited, necessitating some kind of consistency recovery (as // preferable to just an error). func TestBuild_Registry(t *testing.T) { testRegistry(NewBuildCmd, t) } // TestBuild_RegistryLoads ensures that a function with a defined registry // will use this when recalculating .Image on build when no --image is // explicitly provided. func TestBuild_RegistryLoads(t *testing.T) { testRegistryLoads(NewBuildCmd, t) } // TestBuild_RegistryOrImageRequired ensures that when no registry or image are // provided (or exist on the function already), and the client has not been // instantiated with a default registry, an ErrRegistryRequired is received. func TestBuild_RegistryOrImageRequired(t *testing.T) { testRegistryOrImageRequired(NewBuildCmd, t) } // TestBuild_BaseImage ensures that base image is used only with the right // builders and propagates into f.Build.BaseImage func TestBuild_BaseImage(t *testing.T) { testBaseImage(NewBuildCmd, t) } // TestBuild_Push ensures that the build command properly pushes and respects // the --push flag. // - Push triggered after a successful build // - Push not triggered after an unsuccessful build // - Push can be disabled func TestBuild_Push(t *testing.T) { root := FromTempDirectory(t) f := fn.Function{ Root: root, Name: "myfunc", Runtime: "go", Registry: "example.com/alice", } if _, err := fn.New().Init(f); err != nil { t.Fatal(err) } var ( builder = mock.NewBuilder() pusher = mock.NewPusher() ) cmd := NewBuildCmd(NewTestClient(fn.WithRegistry(TestRegistry), fn.WithBuilder(builder), fn.WithPusher(pusher))) cmd.SetArgs([]string{}) if err := cmd.Execute(); err != nil { t.Fatal(err) } // Assert there was no push if pusher.PushInvoked { t.Fatal("push should not be invoked by default") } // Execute with push enabled cmd.SetArgs([]string{"--push"}) if err := cmd.Execute(); err != nil { t.Fatal(err) } // Assert there was a push if !pusher.PushInvoked { t.Fatal("push should be invoked when requested and a successful build") } // Execute with push enabled but with a failed build builder.BuildFn = func(f fn.Function) error { return errors.New("mock error") } pusher.PushInvoked = false _ = cmd.Execute() // expected error // Assert push was not invoked when the build failed if pusher.PushInvoked { t.Fatal("push should not be invoked on a failed build") } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |