How to use TestDir method of loader_test Package

Best K6 code snippet using loader_test.TestDir

loader_test.go

Source:loader_test.go Github

copy

Full Screen

1/*2Copyright 2018 Heptio Inc.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 loader14import (15 "path"16 "reflect"17 "sort"18 "testing"19 "github.com/vmware-tanzu/sonobuoy/pkg/plugin"20 "github.com/vmware-tanzu/sonobuoy/pkg/plugin/driver/daemonset"21 "github.com/vmware-tanzu/sonobuoy/pkg/plugin/driver/job"22 "github.com/vmware-tanzu/sonobuoy/pkg/plugin/manifest"23 "github.com/pkg/errors"24 corev1 "k8s.io/api/core/v1"25)26func TestFindPlugins(t *testing.T) {27 testdir := path.Join("testdata", "plugin.d")28 plugins, err := findPlugins(testdir)29 if err != nil {30 t.Fatalf("unexpected err %v", err)31 }32 expected := []string{33 "testdata/plugin.d/daemonset.yaml",34 "testdata/plugin.d/invalid.yml",35 "testdata/plugin.d/job.yml",36 }37 sort.Strings(plugins)38 if !reflect.DeepEqual(expected, plugins) {39 t.Errorf("expected %v, got %v", expected, plugins)40 }41}42func TestLoadNonexistentPlugin(t *testing.T) {43 _, err := loadDefinitionFromFile("non/existent/path")44 if errors.Cause(err).Error() != "open non/existent/path: no such file or directory" {45 t.Errorf("Expected ErrNotExist, got %v", errors.Cause(err))46 }47}48func TestLoadValidPlugin(t *testing.T) {49 jobDefFileName := "testdata/plugin.d/job.yml"50 jobDefFile, err := loadDefinitionFromFile(jobDefFileName)51 if err != nil {52 t.Fatalf("Unexpected error reading job plugin: %v", err)53 }54 jobDef, err := loadDefinition(jobDefFile)55 if err != nil {56 t.Fatalf("Unexpected error loading job plugin: %v", err)57 }58 if jobDef.SonobuoyConfig.Driver != "Job" {59 t.Errorf("expected driver Job, got %q", jobDef.SonobuoyConfig.Driver)60 }61 if jobDef.SonobuoyConfig.PluginName != "test-job-plugin" {62 t.Errorf("expected name test-job-plugin, got %q", jobDef.SonobuoyConfig.PluginName)63 }64 if jobDef.Spec.Image != "gcr.io/heptio-images/heptio-e2e:master" {65 t.Errorf("expected name gcr.io/heptio-images/heptio-e2e:master, got %q", jobDef.Spec.Image)66 }67 daemonDefFileName := "testdata/plugin.d/daemonset.yaml"68 daemonDefFile, err := loadDefinitionFromFile(daemonDefFileName)69 if err != nil {70 t.Fatalf("Unexpected error creating daemonset plugin: %v", err)71 }72 daemonDef, err := loadDefinition(daemonDefFile)73 if err != nil {74 t.Fatalf("Unexpected error loading daemonset plugin: %v", err)75 }76 if daemonDef.SonobuoyConfig.Driver != "DaemonSet" {77 t.Errorf("expected driver DaemonSet, got %q", daemonDef.SonobuoyConfig.Driver)78 }79 if daemonDef.SonobuoyConfig.PluginName != "test-daemon-set-plugin" {80 t.Errorf("expected name test-daemon-set-plugin, got %q", daemonDef.SonobuoyConfig.PluginName)81 }82 if daemonDef.Spec.Image != "gcr.io/heptio-images/heptio-e2e:master" {83 t.Errorf("expected name gcr.io/heptio-images/heptio-e2e:master, got %q", jobDef.Spec.Image)84 }85}86func TestLoadValidPluginWithSkipCleanup(t *testing.T) {87 testCases := []struct {88 desc string89 jobDefFileName string90 expectedValue bool91 }{92 {93 desc: "skip-cleanup set to true results in true",94 jobDefFileName: "testdata/skip-cleanup/set-true.yml",95 expectedValue: true,96 },97 {98 desc: "skip-cleanup set to true results in true",99 jobDefFileName: "testdata/skip-cleanup/set-false.yml",100 expectedValue: false,101 },102 {103 desc: "skip-cleanup not set defaults to false",104 jobDefFileName: "testdata/skip-cleanup/not-set.yml",105 expectedValue: false,106 },107 }108 for _, tc := range testCases {109 t.Run(tc.desc, func(t *testing.T) {110 jobDefFile, err := loadDefinitionFromFile(tc.jobDefFileName)111 if err != nil {112 t.Fatalf("Unexpected error reading job plugin: %v", err)113 }114 jobDef, err := loadDefinition(jobDefFile)115 if err != nil {116 t.Fatalf("Unexpected error loading job plugin: %v", err)117 }118 if jobDef.SonobuoyConfig.SkipCleanup != tc.expectedValue {119 t.Errorf("expected skip-cleanup to be %v but was %v", tc.expectedValue, jobDef.SonobuoyConfig.SkipCleanup)120 }121 })122 }123}124func TestLoadJobPlugin(t *testing.T) {125 namespace := "loader_test"126 image := "gcr.io/heptio-images/sonobuoy:latest"127 jobDef := manifest.Manifest{128 SonobuoyConfig: manifest.SonobuoyConfig{129 Driver: "Job",130 PluginName: "test-job-plugin",131 },132 Spec: manifest.Container{133 Container: corev1.Container{134 Image: "gcr.io/heptio-images/heptio-e2e:master",135 },136 },137 }138 pluginIface, err := loadPlugin(jobDef, namespace, image, "Always", "image-pull-secrets", nil)139 if err != nil {140 t.Fatalf("unexpected error loading plugin: %v", err)141 }142 jobPlugin, ok := pluginIface.(*job.Plugin)143 if !ok {144 t.Fatalf("loaded plugin not a job.Plugin")145 }146 if jobPlugin.GetName() != "test-job-plugin" {147 t.Errorf("expected plugin name 'test-job-plugin', got '%v'", jobPlugin.GetName())148 }149 if jobPlugin.Definition.Spec.Image != "gcr.io/heptio-images/heptio-e2e:master" {150 t.Errorf("expected plugin name 'gcr.io/heptio-images/heptio-e2e:master', got '%v'", jobPlugin.Definition.Spec.Image)151 }152 if jobPlugin.Namespace != namespace {153 t.Errorf("expected plugin name '%q', got '%v'", namespace, jobPlugin.Namespace)154 }155 if jobPlugin.ImagePullSecrets != "image-pull-secrets" {156 t.Errorf("Expected imagePullSecrets with name %v but got %v", "image-pull-secret", jobPlugin.ImagePullSecrets)157 }158}159func TestLoadDaemonSet(t *testing.T) {160 namespace := "loader_test"161 image := "gcr.io/heptio-images/sonobuoy:latest"162 daemonDef := manifest.Manifest{163 SonobuoyConfig: manifest.SonobuoyConfig{164 Driver: "DaemonSet",165 PluginName: "test-daemon-set-plugin",166 },167 Spec: manifest.Container{168 Container: corev1.Container{169 Image: "gcr.io/heptio-images/heptio-e2e:master",170 },171 },172 }173 pluginIface, err := loadPlugin(daemonDef, namespace, image, "Always", "image-pull-secrets", nil)174 if err != nil {175 t.Fatalf("unexpected error loading plugin: %v", err)176 }177 daemonPlugin, ok := pluginIface.(*daemonset.Plugin)178 if !ok {179 t.Fatalf("loaded plugin not a daemon.Plugin")180 }181 if daemonPlugin.GetName() != "test-daemon-set-plugin" {182 t.Errorf("expected plugin name 'test-daemon-set-plugin', got '%v'", daemonPlugin.GetName())183 }184 if daemonPlugin.Definition.Spec.Image != "gcr.io/heptio-images/heptio-e2e:master" {185 t.Errorf("expected plugin name 'gcr.io/heptio-images/heptio-e2e:master', got '%v'", daemonPlugin.Definition.Spec.Image)186 }187 if daemonPlugin.Namespace != namespace {188 t.Errorf("expected plugin name '%q', got '%v'", namespace, daemonPlugin.Namespace)189 }190 if daemonPlugin.ImagePullSecrets != "image-pull-secrets" {191 t.Errorf("Expected imagePullSecrets with name %v but got %v", "image-pull-secret", daemonPlugin.ImagePullSecrets)192 }193}194func TestFilterList(t *testing.T) {195 definitions := []manifest.Manifest{196 {SonobuoyConfig: manifest.SonobuoyConfig{PluginName: "test1"}},197 {SonobuoyConfig: manifest.SonobuoyConfig{PluginName: "test2"}},198 }199 selections := []plugin.Selection{200 {Name: "test1"},201 {Name: "test3"},202 }203 expected := []manifest.Manifest{definitions[0]}204 filtered := filterPluginDef(definitions, selections)205 if !reflect.DeepEqual(filtered, expected) {206 t.Errorf("expected %+#v, got %+#v", expected, filtered)207 }208}209func TestLoadAllPlugins(t *testing.T) {210 testcases := []struct {211 testname string212 namespace string213 sonobuoyImage string214 imagePullPolicy string215 imagePullSecrets string216 customAnnotations map[string]string217 searchPath []string218 selections []plugin.Selection219 expectedPluginNames []string220 }{221 {222 testname: "ensure duplicate paths do not result in duplicate loaded plugins.",223 searchPath: []string{path.Join("testdata", "plugin.d"), path.Join("testdata", "plugin.d")},224 selections: []plugin.Selection{225 {Name: "test-job-plugin"},226 {Name: "test-daemon-set-plugin"},227 },228 expectedPluginNames: []string{"test-job-plugin", "test-daemon-set-plugin"},229 }, {230 testname: "nil selections defaults to run all",231 searchPath: []string{path.Join("testdata", "onlyvalid")},232 selections: nil,233 expectedPluginNames: []string{"test-job-plugin", "test-daemon-set-plugin"},234 }, {235 testname: "empty (non-nil) selection runs none",236 searchPath: []string{path.Join("testdata", "plugin.d")},237 selections: []plugin.Selection{},238 expectedPluginNames: []string{},239 },240 }241 for _, tc := range testcases {242 t.Run(tc.testname, func(t *testing.T) {243 plugins, err := LoadAllPlugins(tc.namespace, tc.sonobuoyImage, tc.imagePullPolicy, tc.imagePullSecrets, tc.customAnnotations, tc.searchPath, tc.selections)244 if err != nil {245 t.Fatalf("error loading all plugins: %v", err)246 }247 if len(plugins) != len(tc.expectedPluginNames) {248 t.Fatalf("expected %v plugins but got %v", len(tc.expectedPluginNames), len(plugins))249 }250 for i, plugin := range plugins {251 found := false252 for _, expectedPlugin := range tc.expectedPluginNames {253 if plugin.GetName() == expectedPlugin {254 found = true255 }256 }257 if !found {258 t.Fatalf("Expected %v but got %v", tc.expectedPluginNames[i], plugin.GetName())259 }260 }261 })262 }263}...

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := ir.NewModule()4 f := m.NewFunc("test", types.Void)5 entry := f.NewBlock("entry")6 c := constant.NewInt(types.I32, 42)7 entry.NewRet(c)8 if err := verifier.VerifyModule(m); err != nil {9 panic(err)10 }11 fmt.Println(m)12}13import (14func main() {15 m := ir.NewModule()16 f := m.NewFunc("test", types.Void)17 entry := f.NewBlock("entry")18 c := constant.NewInt(types.I32, 42)19 entry.NewRet(c)20 if err := verifier.VerifyModule(m); err != nil {21 panic(err)22 }23 fmt.Println(m

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(loader_test.TestDir())4}5import (6func TestDir() string {7 _, filename, _, _ := runtime.Caller(1)8 return filepath.Dir(filename)9}10func main() {11 fmt.Println(TestDir())12}

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 loader := config.NewConfig("ini", "conf/app.conf")4 fmt.Println(loader.String("appname"))5 fmt.Println(loader.String("httpport"))6 fmt.Println(loader.String("mysql::username"))7 fmt.Println(loader.String("mysql::password"))8}9import (10func main() {11 loader := config.NewConfig("ini", "conf/app.conf")12 fmt.Println(loader.String("appname"))13 fmt.Println(loader.String("httpport"))14 fmt.Println(loader.String("mysql::username"))15 fmt.Println(loader.String("mysql::password"))16}17import (18func main() {19 loader := config.NewConfig("ini", "conf/app.conf")20 fmt.Println(loader.String("appname"))21 fmt.Println(loader.String("httpport"))22 fmt.Println(loader.String("mysql::username"))23 fmt.Println(loader.String("mysql::password"))24}25import (26func main() {27 loader := config.NewConfig("ini", "conf/app.conf")28 fmt.Println(loader.String("appname"))29 fmt.Println(loader.String("httpport"))30 fmt.Println(loader.String("mysql::username"))31 fmt.Println(loader.String("mysql::password"))32}33import (34func main() {35 loader := config.NewConfig("ini", "conf/app.conf")36 fmt.Println(loader.String("appname"))37 fmt.Println(loader.String("httpport"))38 fmt.Println(loader.String("mysql::username"))39 fmt.Println(loader.String("mysql::password"))40}41import (42func main() {43 loader := config.NewConfig("ini", "conf/app.conf")

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ld := loader.New()4 ld.TestDir()5 fmt.Println("done")6}7import (8type Loader struct {9}10func New() *Loader {11 return &Loader{}12}13func (l *Loader) TestDir() {14 dir, _ := os.Getwd()15 fmt.Println(dir)16}17import (18func TestDir(t *testing.T) {19 ld := New()20 ld.TestDir()21}22import (23func TestDir(t *testing.T) {24 ld := loader.New()25 ld.TestDir()26}27 imports loader28 imports loader: import cycle not allowed29--- PASS: TestDir (0.00s)

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1func main() {2 l := new(loader_test)3 l.TestDir()4}5func (l *loader_test) TestDir() {6 l.TestDir()7}8main.main()

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l := loader_test.NewLoader()4 l.TestDir()5}6import (7func main() {8 l := loader_test.NewLoader()9 l.TestFile()10}11import (12type Loader struct {13}14func NewLoader() *Loader {15 return &Loader{Dir: "test"}16}17func (l *Loader) TestDir() {18 err := filepath.Walk(l.Dir, func(path string, info os.FileInfo, err error) error {19 if err != nil {20 }21 if info.IsDir() {22 fmt.Println("Dir: ", path)23 }24 })25 if err != nil {26 fmt.Println(err)27 }28}29func (l *Loader) TestFile() {30 files, err := ioutil.ReadDir(l.Dir)31 if err != nil {32 fmt.Println(err)33 }34 for _, f := range files {35 if f.IsDir() {36 fmt.Println("Dir: ", f.Name())37 } else {38 fmt.Println("File: ", f.Name())39 }40 }41}

Full Screen

Full Screen

TestDir

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l := loader.NewLoader()4 l.AddPath(".")5 l.AddPath("../../../../usr/lib/go/src/pkg")6 l.AddPath("../../../../usr/lib/go/src/pkg/math")7 l.AddPath("../../../../usr/lib/go/src/pkg/strings")8 l.AddPath("../../../../usr/lib/go/src/pkg/unicode")9 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")10 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")11 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")12 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")13 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")14 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")15 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")16 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")17 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")18 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")19 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")20 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")21 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")22 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")23 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")24 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")25 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")26 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")27 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")28 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")29 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")30 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf16")31 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/utf8")32 l.AddPath("../../../../usr/lib/go/src/pkg/unicode/

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.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful