github.com/0xKiwi/rules_go@v0.24.3/tests/core/go_plugin/all_test.go (about)

     1  package main_test
     2  
     3  import (
     4  	"os"
     5  	"plugin"
     6  	"testing"
     7  )
     8  
     9  const HelloWorld = "Hello, world!"
    10  
    11  func TestPluginCreated(t *testing.T) {
    12  	_, err := os.Stat("plugin.so")
    13  	if err != nil {
    14  		t.Error(err)
    15  	}
    16  }
    17  
    18  func TestPluginWorks(t *testing.T) {
    19  	p, err := plugin.Open("plugin.so")
    20  	if err != nil {
    21  		t.Error(err)
    22  	}
    23  
    24  	f, err := p.Lookup("Hi")
    25  	if err != nil {
    26  		t.Error(err)
    27  	}
    28  
    29  	helloWorld := f.(func() string)()
    30  	if helloWorld != HelloWorld {
    31  		t.Errorf("expected %#v, got %#v", HelloWorld, helloWorld)
    32  	}
    33  }