How to use FullName method of testkube Package

Best Testkube code snippet using testkube.FullName

install.go

Source:install.go Github

copy

Full Screen

1/*2The MIT License (MIT)3Copyright © 2022 Kubeshop4Permission is hereby granted, free of charge, to any person obtaining a copy5of this software and associated documentation files (the "Software"), to deal6in the Software without restriction, including without limitation the rights7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8copies of the Software, and to permit persons to whom the Software is9furnished to do so, subject to the following conditions:10The above copyright notice and this permission notice shall be included in11all copies or substantial portions of the Software.12THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18THE SOFTWARE.19*/20package cmd21import (22 "encoding/json"23 "fmt"24 "os"25 "os/exec"26 "strings"27 "github.com/kubeshop/testkube/pkg/process"28 "github.com/kubeshop/testkube/pkg/ui"29 "github.com/spf13/cobra"30)31var (32 noApi bool33 noDashboard bool34 noEnvoyFleet bool35 releaseName, releaseNamespace string36)37func init() {38 rootCmd.AddCommand(installCmd)39 installCmd.Flags().StringVar(&releaseName, "name", "kusk-gateway", "installation name")40 installCmd.Flags().StringVar(&releaseNamespace, "namespace", "kusk-system", "namespace to install in")41 installCmd.Flags().BoolVar(&noDashboard, "no-dashboard", false, "don't the install dashboard")42 installCmd.Flags().BoolVar(&noApi, "no-api", false, "don't install the api. Setting this flag implies --no-dashboard")43 installCmd.Flags().BoolVar(&noEnvoyFleet, "no-envoy-fleet", false, "don't install any envoy fleets")44}45var installCmd = &cobra.Command{46 Use: "install",47 Short: "Install kusk-gateway, envoy-fleet, api, and dashboard in a single command",48 Long: `49 Install kusk-gateway, envoy-fleet, api, and dashboard in a single command.50 $ kusk install51 Will install kusk-gateway, a public (for your APIS) and private (for the kusk dashboard and api) 52 envoy-fleet, api, and dashboard in the kusk-system namespace using helm.53 $ kusk install --name=my-release --namespace=my-namespace54 Will create a helm release named with --name in the namespace specified by --namespace.55 $ kusk install --no-dashboard --no-api --no-envoy-fleet56 Will install kusk-gateway, but not the dashboard, api, or envoy-fleet.57 `,58 Run: func(cmd *cobra.Command, args []string) {59 helmPath, err := exec.LookPath("helm")60 ui.ExitOnError("looking for helm", err)61 ui.Info("adding the kubeshop helm repository")62 err = addKubeshopHelmRepo(helmPath)63 ui.ExitOnError("adding kubeshop repo", err)64 ui.Info(ui.Green("done"))65 ui.Info("fetching the latest charts")66 err = updateHelmRepos(helmPath)67 ui.ExitOnError("updating helm repositories", err)68 ui.Info(ui.Green("done"))69 releases, err := listReleases(helmPath, releaseName, releaseNamespace)70 ui.ExitOnError("listing existing releases", err)71 if _, kuskGatewayInstalled := releases[releaseName]; !kuskGatewayInstalled {72 ui.Info("installing Kusk Gateway")73 err = installKuskGateway(helmPath, releaseName, releaseNamespace)74 ui.ExitOnError("Installing kusk gateway", err)75 ui.Info(ui.Green("done"))76 } else {77 ui.Info("kusk gateway already installed, skipping. To upgrade to a new version run kusk upgrade")78 }79 envoyFleetName := fmt.Sprintf("%s-envoy-fleet", releaseName)80 if _, publicEnvoyFleetInstalled := releases[envoyFleetName]; !publicEnvoyFleetInstalled {81 if !noEnvoyFleet {82 ui.Info("installing Envoy Fleet")83 err = installPublicEnvoyFleet(helmPath, envoyFleetName, releaseNamespace)84 ui.ExitOnError("Installing envoy fleet", err)85 ui.Info(ui.Green("done"))86 } else {87 ui.Info(ui.LightYellow("--no-envoy-fleet set - skipping envoy fleet installation"))88 }89 } else {90 ui.Info("envoy fleet already installed, skipping. To upgrade to a new version run kusk upgrade")91 }92 if noApi {93 ui.Info(ui.LightYellow("--no-api set - skipping api installation"))94 return95 }96 if !noEnvoyFleet {97 envoyFleetName = fmt.Sprintf("%s-private-envoy-fleet", releaseName)98 if _, privateEnvoyFleetInstalled := releases[envoyFleetName]; !privateEnvoyFleetInstalled {99 err = installPrivateEnvoyFleet(helmPath, envoyFleetName, releaseNamespace)100 ui.ExitOnError("Installing envoy fleet", err)101 } else {102 ui.Info("private envoy fleet already installed, skipping. To upgrade to a new version run kusk upgrade")103 }104 }105 apiReleaseName := fmt.Sprintf("%s-api", releaseName)106 if _, apiInstalled := releases[apiReleaseName]; !apiInstalled {107 ui.Info("installing Kusk API")108 err = installApi(helmPath, apiReleaseName, releaseNamespace, envoyFleetName)109 ui.ExitOnError("Installing api", err)110 ui.Info(ui.Green("done"))111 } else {112 ui.Info("api already installed, skipping. To upgrade to a new version run kusk upgrade")113 }114 if noDashboard {115 ui.Info(ui.LightYellow("--no-dashboard set - skipping dashboard installation"))116 printPortForwardInstructions("api", releaseNamespace, envoyFleetName)117 return118 }119 dashboardReleaseName := fmt.Sprintf("%s-dashboard", releaseName)120 if _, ok := releases[dashboardReleaseName]; !ok {121 ui.Info("installing Kusk Dashboard")122 err = installDashboard(helmPath, dashboardReleaseName, releaseNamespace, envoyFleetName)123 ui.ExitOnError("Installing dashboard", err)124 ui.Info(ui.Green("done"))125 } else {126 ui.Info("dashboard already installed, skipping. To upgrade to a new version run kusk upgrade")127 }128 printPortForwardInstructions("dashboard", releaseNamespace, envoyFleetName)129 },130}131func printPortForwardInstructions(service, releaseNamespace, envoyFleetName string) {132 ui.Info(ui.Green("To access the " + service + ", port forward to the envoy-fleet service that exposes it"))133 ui.Info(ui.LightBlue(fmt.Sprintf("\t$ kubectl port-forward -n %s svc/%s 8080:80", releaseNamespace, envoyFleetName)))134 endpoint := "http://localhost:8080/"135 if service == "api" {136 endpoint += "api"137 }138 ui.Info(ui.LightBlue("\tand go " + endpoint))139}140func addKubeshopHelmRepo(helmPath string) error {141 _, err := process.Execute(helmPath, "repo", "add", "kubeshop", "https://kubeshop.github.io/helm-charts/")142 if err != nil && !strings.Contains(err.Error(), "Error: repository name (kubeshop) already exists, please specify a different name") {143 return err144 }145 return nil146}147func updateHelmRepos(helmPath string) error {148 _, err := process.Execute(helmPath, "repo", "update")149 return err150}151func listReleases(helmPath, releaseName, releaseNamespace string) (map[string]string, error) {152 command := []string{153 "ls",154 "-n", releaseNamespace,155 "-o", "json",156 }157 out, err := process.Execute(helmPath, command...)158 if err != nil {159 return nil, err160 }161 var releases []struct {162 Name string `json:"name"`163 Chart string `json:"chart"`164 }165 if err := json.Unmarshal(out, &releases); err != nil {166 return nil, err167 }168 releaseMap := make(map[string]string)169 for _, release := range releases {170 if strings.HasPrefix(release.Name, releaseName) {171 releaseMap[release.Name] = release.Chart172 }173 }174 return releaseMap, nil175}176func installKuskGateway(helmPath, releaseName, releaseNamespace string) error {177 analyticsEnabled := "true"178 if enabled, ok := os.LookupEnv("ANALYTICS_ENABLED"); ok {179 analyticsEnabled = enabled180 }181 command := []string{182 "upgrade",183 "--install",184 "--wait",185 "--create-namespace",186 "--namespace",187 releaseNamespace,188 "--set", fmt.Sprintf("fullnameOverride=%s", releaseName),189 "--set", fmt.Sprintf("analytics.enabled=%s", analyticsEnabled),190 releaseName,191 "kubeshop/kusk-gateway",192 }193 out, err := process.Execute(helmPath, command...)194 if err != nil {195 return err196 }197 ui.Debug("helm install kusk gateway output", string(out))198 return nil199}200func installPublicEnvoyFleet(helmPath, releaseName, releaseNamespace string) error {201 return installEnvoyFleet(helmPath, releaseName, releaseNamespace, "LoadBalancer")202}203func installPrivateEnvoyFleet(helmPath, releaseName, releaseNamespace string) error {204 return installEnvoyFleet(helmPath, releaseName, releaseNamespace, "ClusterIP")205}206func installEnvoyFleet(helmPath, releaseName, releaseNamespace, serviceType string) error {207 command := []string{208 "upgrade",209 "--install",210 "--wait",211 "--create-namespace",212 "--namespace",213 releaseNamespace,214 "--set", fmt.Sprintf("fullnameOverride=%s", releaseName),215 "--set", fmt.Sprintf("service.type=%s", serviceType),216 releaseName,217 "kubeshop/kusk-gateway-envoyfleet",218 }219 out, err := process.Execute(helmPath, command...)220 if err != nil {221 return err222 }223 ui.Debug("helm install envoy fleet output", string(out))224 return nil225}226func installApi(helmPath, releaseName, releaseNamespace, envoyFleetName string) error {227 command := []string{228 "upgrade",229 "--install",230 "--wait",231 "--create-namespace",232 "--namespace",233 releaseNamespace,234 "--set", fmt.Sprintf("fullnameOverride=%s", releaseName),235 "--set", fmt.Sprintf("envoyfleet.name=%s", envoyFleetName),236 "--set", fmt.Sprintf("envoyfleet.namespace=%s", releaseNamespace),237 releaseName,238 "kubeshop/kusk-gateway-api",239 }240 out, err := process.Execute(helmPath, command...)241 if err != nil {242 return err243 }244 ui.Debug("helm install api output", string(out))245 return nil246}247func installDashboard(helmPath, releaseName, releaseNamespace, envoyFleetName string) error {248 command := []string{249 "upgrade",250 "--install",251 "--wait",252 "--create-namespace",253 "--namespace",254 releaseNamespace,255 "--set", fmt.Sprintf("fullnameOverride=%s", releaseName),256 "--set", fmt.Sprintf("envoyfleet.name=%s", envoyFleetName),257 "--set", fmt.Sprintf("envoyfleet.namespace=%s", releaseNamespace),258 releaseName,259 "kubeshop/kusk-gateway-dashboard",260 }261 out, err := process.Execute(helmPath, command...)262 if err != nil {263 return err264 }265 ui.Debug("helm install dashboard output", string(out))266 return nil267}...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1/*2Copyright 2021.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package main14import (15 "encoding/base64"16 "flag"17 "os"18 // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)19 // to ensure that exec-entrypoint and run can make use of them.20 zapUber "go.uber.org/zap"21 "go.uber.org/zap/zapcore"22 _ "k8s.io/client-go/plugin/pkg/client/auth"23 "github.com/kelseyhightower/envconfig"24 "k8s.io/apimachinery/pkg/runtime"25 utilruntime "k8s.io/apimachinery/pkg/util/runtime"26 clientgoscheme "k8s.io/client-go/kubernetes/scheme"27 ctrl "sigs.k8s.io/controller-runtime"28 "sigs.k8s.io/controller-runtime/pkg/healthz"29 "sigs.k8s.io/controller-runtime/pkg/log/zap"30 executorv1 "github.com/kubeshop/testkube-operator/apis/executor/v1"31 testkubev1 "github.com/kubeshop/testkube-operator/apis/script/v1"32 testkubev2 "github.com/kubeshop/testkube-operator/apis/script/v2"33 testsv1 "github.com/kubeshop/testkube-operator/apis/tests/v1"34 testsv2 "github.com/kubeshop/testkube-operator/apis/tests/v2"35 testsv3 "github.com/kubeshop/testkube-operator/apis/tests/v3"36 testsuitev1 "github.com/kubeshop/testkube-operator/apis/testsuite/v1"37 testsuitev2 "github.com/kubeshop/testkube-operator/apis/testsuite/v2"38 executorcontrollers "github.com/kubeshop/testkube-operator/controllers/executor"39 scriptcontrollers "github.com/kubeshop/testkube-operator/controllers/script"40 testscontrollers "github.com/kubeshop/testkube-operator/controllers/tests"41 testsuitecontrollers "github.com/kubeshop/testkube-operator/controllers/testsuite"42 "github.com/kubeshop/testkube-operator/pkg/cronjob"43 //+kubebuilder:scaffold:imports44)45var (46 scheme = runtime.NewScheme()47 setupLog = ctrl.Log.WithName("setup")48)49// config for HTTP server50type config struct {51 Port int52 Fullname string53 TemplateCronjob string `split_words:"true"`54}55func init() {56 utilruntime.Must(clientgoscheme.AddToScheme(scheme))57 utilruntime.Must(testkubev1.AddToScheme(scheme))58 utilruntime.Must(executorv1.AddToScheme(scheme))59 utilruntime.Must(testsv1.AddToScheme(scheme))60 utilruntime.Must(testkubev2.AddToScheme(scheme))61 utilruntime.Must(testsuitev1.AddToScheme(scheme))62 utilruntime.Must(testsv2.AddToScheme(scheme))63 utilruntime.Must(testsv3.AddToScheme(scheme))64 utilruntime.Must(testsuitev2.AddToScheme(scheme))65 //+kubebuilder:scaffold:scheme66}67func main() {68 var metricsAddr string69 var enableLeaderElection bool70 var probeAddr string71 flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")72 flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")73 flag.BoolVar(&enableLeaderElection, "leader-elect", false,74 "Enable leader election for controller manager. "+75 "Enabling this will ensure there is only one active controller manager.")76 flag.Parse()77 setLogger()78 var httpConfig config79 err := envconfig.Process("APISERVER", &httpConfig)80 // Do we want to panic here or just ignore the err81 if err != nil {82 panic(err)83 }84 var templateCronjob string85 if httpConfig.TemplateCronjob != "" {86 data, err := base64.StdEncoding.DecodeString(httpConfig.TemplateCronjob)87 if err != nil {88 panic(err)89 }90 templateCronjob = string(data)91 }92 mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{93 Scheme: scheme,94 MetricsBindAddress: metricsAddr,95 Port: 9443,96 HealthProbeBindAddress: probeAddr,97 LeaderElection: enableLeaderElection,98 LeaderElectionID: "47f0dfc1.testkube.io",99 })100 if err != nil {101 setupLog.Error(err, "unable to start manager")102 os.Exit(1)103 }104 if err = (&scriptcontrollers.ScriptReconciler{105 Client: mgr.GetClient(),106 Scheme: mgr.GetScheme(),107 }).SetupWithManager(mgr); err != nil {108 setupLog.Error(err, "unable to create controller", "controller", "Script")109 os.Exit(1)110 }111 if err = (&executorcontrollers.ExecutorReconciler{112 Client: mgr.GetClient(),113 Scheme: mgr.GetScheme(),114 }).SetupWithManager(mgr); err != nil {115 setupLog.Error(err, "unable to create controller", "controller", "Executor")116 os.Exit(1)117 }118 if err = (&testscontrollers.TestReconciler{119 Client: mgr.GetClient(),120 Scheme: mgr.GetScheme(),121 CronJobClient: cronjob.NewClient(mgr.GetClient(), httpConfig.Fullname, httpConfig.Port, templateCronjob),122 }).SetupWithManager(mgr); err != nil {123 setupLog.Error(err, "unable to create controller", "controller", "Test")124 os.Exit(1)125 }126 if err = (&testsuitecontrollers.TestSuiteReconciler{127 Client: mgr.GetClient(),128 Scheme: mgr.GetScheme(),129 CronJobClient: cronjob.NewClient(mgr.GetClient(), httpConfig.Fullname, httpConfig.Port, templateCronjob),130 }).SetupWithManager(mgr); err != nil {131 setupLog.Error(err, "unable to create controller", "controller", "TestSuite")132 os.Exit(1)133 }134 if err = (&executorcontrollers.WebhookReconciler{135 Client: mgr.GetClient(),136 Scheme: mgr.GetScheme(),137 }).SetupWithManager(mgr); err != nil {138 setupLog.Error(err, "unable to create controller", "controller", "Webhook")139 os.Exit(1)140 }141 //+kubebuilder:scaffold:builder142 if os.Getenv("ENABLE_WEBHOOKS") != "false" {143 if err = (&testkubev1.Script{}).SetupWebhookWithManager(mgr); err != nil {144 setupLog.Error(err, "unable to create webhook", "webhook", "Script")145 os.Exit(1)146 }147 if err = (&testkubev2.Script{}).SetupWebhookWithManager(mgr); err != nil {148 setupLog.Error(err, "unable to create webhook", "webhook", "Script")149 os.Exit(1)150 }151 if err = (&testsv1.Test{}).SetupWebhookWithManager(mgr); err != nil {152 setupLog.Error(err, "unable to create webhook", "webhook", "Test")153 os.Exit(1)154 }155 if err = (&testsv2.Test{}).SetupWebhookWithManager(mgr); err != nil {156 setupLog.Error(err, "unable to create webhook", "webhook", "Test")157 os.Exit(1)158 }159 if err = (&testsv3.Test{}).SetupWebhookWithManager(mgr); err != nil {160 setupLog.Error(err, "unable to create webhook", "webhook", "Test")161 os.Exit(1)162 }163 if err = (&testsuitev1.TestSuite{}).SetupWebhookWithManager(mgr); err != nil {164 setupLog.Error(err, "unable to create webhook", "webhook", "TestSuite")165 os.Exit(1)166 }167 if err = (&testsuitev2.TestSuite{}).SetupWebhookWithManager(mgr); err != nil {168 setupLog.Error(err, "unable to create webhook", "webhook", "TestSuite")169 os.Exit(1)170 }171 }172 if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {173 setupLog.Error(err, "unable to set up health check")174 os.Exit(1)175 }176 if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {177 setupLog.Error(err, "unable to set up ready check")178 os.Exit(1)179 }180 setupLog.Info("starting manager")181 if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {182 setupLog.Error(err, "problem running manager")183 os.Exit(1)184 }185}186// setLogger sets up the zap logger to print error, panic and fatal messages to stderr and lower level messages to stdout187func setLogger() {188 highPriority := zapUber.LevelEnablerFunc(func(lvl zapcore.Level) bool {189 return lvl >= zapcore.ErrorLevel190 })191 lowPriority := zapUber.LevelEnablerFunc(func(lvl zapcore.Level) bool {192 return lvl < zapcore.ErrorLevel193 })194 consoleDebugging := zapcore.Lock(os.Stdout)195 consoleErrors := zapcore.Lock(os.Stderr)196 consoleEncoder := zapcore.NewConsoleEncoder(zapUber.NewDevelopmentEncoderConfig())197 updateZapcore := func(c zapcore.Core) zapcore.Core {198 core := zapcore.NewTee(199 zapcore.NewCore(consoleEncoder, consoleErrors, highPriority),200 zapcore.NewCore(consoleEncoder, consoleDebugging, lowPriority),201 )202 return core203 }204 var opts zap.Options205 opts.ZapOpts = append(opts.ZapOpts, zapUber.WrapCore(updateZapcore))206 ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))207}...

Full Screen

Full Screen

testsuite_obj.go

Source:testsuite_obj.go Github

copy

Full Screen

...41 ui.Warn("Test steps:", fmt.Sprintf("%d", len(steps)))42 d := [][]string{{"Name", "Stop on failure", "Type"}}43 for _, step := range steps {44 d = append(d, []string{45 step.FullName(),46 fmt.Sprintf("%v", step.StopTestOnFailure),47 string(*step.Type()),48 })49 }50 ui.Table(ui.NewArrayTable(d), ui.Writer)51 ui.NL()52 return nil53}...

Full Screen

Full Screen

FullName

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "testkube"3func main() {4 fmt.Println(t.FullName())5}6We have created a main package which imports the

Full Screen

Full Screen

FullName

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 t.FullName("test", "kube")4}5import "fmt"6func main() {7 t.FullName("test", "kube")8}9import "fmt"10func main() {11 t.FullName("test", "kube")12}13import "fmt"14func main() {15 t.FullName("test", "kube")16}17import "fmt"18func main() {19 t.FullName("test", "kube")20}21import "fmt"22func main() {23 t.FullName("test", "kube")24}25import "fmt"26func main() {27 t.FullName("test", "kube")28}29import "fmt"30func main() {31 t.FullName("test", "kube")32}33import "fmt"34func main() {35 t.FullName("test", "kube")36}37import "fmt"38func main() {39 t.FullName("test", "kube")40}41import "fmt"42func main() {43 t.FullName("test", "kube")44}

Full Screen

Full Screen

FullName

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(testkube.FullName())4}5import (6func main() {7 fmt.Println(testkube.FullName())8}9import (10func main() {11 fmt.Println(testkube.FullName())12}13import (14func main() {15 fmt.Println(testkube.FullName())16}17import (18func main() {19 fmt.Println(testkube.FullName())20}21import (22func main() {23 fmt.Println(testkube.FullName())24}25import (26func main() {27 fmt.Println(testkube.FullName())28}29import (30func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful