...

Source file src/edge-infra.dev/test/f2/examples/embed/simple/simple_test.go

Documentation: edge-infra.dev/test/f2/examples/embed/simple

     1  package simple
     2  
     3  import (
     4  	"context"
     5  	"embed"
     6  	"os"
     7  	"testing"
     8  
     9  	"gotest.tools/v3/assert"
    10  
    11  	"edge-infra.dev/test/f2"
    12  )
    13  
    14  // embed the testdata directory
    15  //
    16  //go:embed testdata
    17  var testdata embed.FS
    18  
    19  var f f2.Framework
    20  
    21  func TestMain(m *testing.M) {
    22  	f = f2.New(context.Background())
    23  	os.Exit(f.Run(m))
    24  }
    25  
    26  func TestSimpleEmbed(t *testing.T) {
    27  	fin := f2.NewFeature("simple embed feature").
    28  		Test("test embed", func(ctx f2.Context, t *testing.T) f2.Context {
    29  			// read the file using the embed var defined above
    30  			data, err := testdata.ReadFile("testdata/test.json")
    31  			assert.NilError(t, err)
    32  			assert.Equal(t, string(data), `{
    33    "msg": "hello"
    34  }`)
    35  
    36  			return ctx
    37  		}).Feature()
    38  
    39  	f.Test(t, fin)
    40  }
    41  

View as plain text