...

Source file src/edge-infra.dev/test/f2/examples/labels/labels_test.go

Documentation: edge-infra.dev/test/f2/examples/labels

     1  package labels
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"testing"
     7  
     8  	"gotest.tools/v3/assert"
     9  
    10  	"edge-infra.dev/test/f2"
    11  )
    12  
    13  // check the BUILD.bazel file for a list of args you can comment/uncomment
    14  // to see different results based off the labels and skip-labels flags
    15  
    16  // you could also comment out all of the args in BUILD.bazel and run the same
    17  // commands via flags
    18  // ex: bazel test //test/f2/examples/labels/... --test_arg=--labels=boo=hoo
    19  
    20  // another method is using test/config.json
    21  // ex:
    22  //   {
    23  //     "labels": "boo=hoo"
    24  //   }
    25  
    26  var f f2.Framework
    27  
    28  func TestMain(m *testing.M) {
    29  	// you can add labels at the framework or the feature level
    30  	// any label added to the framework will also be added to the feature
    31  	f = f2.New(context.Background(), f2.WithExtensions()).
    32  		WithLabel("test", "label").            // custom labels can have a single value
    33  		WithLabel("foo", "bar", "baz", "boo"). // or a list of values
    34  		Flaky().                               // or use a predefined label
    35  		Component("yada").
    36  		Priviledged("yada").
    37  		WithID("yada").
    38  		Slow().
    39  		Disruptive().
    40  		Serial()
    41  
    42  		// list of labels defined on the framework:
    43  		// map[
    44  		//  component:yada
    45  		// 	disruptive:true
    46  		// 	flaky:true
    47  		// 	foo:bar,baz,boo
    48  		// 	id:yada
    49  		// 	priviledged:yada
    50  		// 	serial:true
    51  		// 	slow:true
    52  		// 	test:label
    53  		// ]
    54  
    55  	os.Exit(f.Run(m))
    56  }
    57  
    58  func TestFeature(t *testing.T) {
    59  	fin := f2.NewFeature("feature 1").
    60  		Test("test hey", func(ctx f2.Context, t *testing.T) f2.Context {
    61  			assert.Assert(t, true)
    62  			t.Log("in feature 1")
    63  
    64  			return ctx
    65  		}).WithLabel("boo", "hoo").Feature()
    66  
    67  	// list of labels defined on the feature:
    68  	// map[
    69  	//  boo:hoo
    70  	//  ... all of the framework labels
    71  	// ]
    72  
    73  	f.Test(t, fin)
    74  }
    75  
    76  func TestAnotherFeature(t *testing.T) {
    77  	fin := f2.NewFeature("feature 2").
    78  		Test("test hey", func(ctx f2.Context, t *testing.T) f2.Context {
    79  			assert.Assert(t, true)
    80  			t.Log("in feature 2")
    81  
    82  			return ctx
    83  		}).WithLabel("boo", "fool").
    84  		Flaky(). // the flaky label is ignored since the framework already defines it
    85  		Feature()
    86  
    87  		// list of labels defined on the feature:
    88  		// map[
    89  		//  boo:fool
    90  		//  ... all of the framework labels
    91  		// ]
    92  	f.Test(t, fin)
    93  }
    94  

View as plain text