github.com/teepark/go-sysvipc@v0.0.0-20200817232735-d7ca6053ea29/common_test.go (about)

     1  package sysvipc
     2  
     3  import (
     4  	"syscall"
     5  	"testing"
     6  )
     7  
     8  func TestFtok(t *testing.T) {
     9  	for _, path := range []string{"common.go", "shm.go", "msg.go", "sem.go"} {
    10  		key, err := Ftok(path, '+')
    11  		if err != nil {
    12  			t.Fatal(err)
    13  		}
    14  
    15  		key2, err := Ftok(path, '+')
    16  		if err != nil {
    17  			t.Fatal(err)
    18  		}
    19  
    20  		if key != key2 {
    21  			t.Errorf("inconsistent result for %s and '+'", path)
    22  		}
    23  	}
    24  
    25  	if _, err := Ftok("sem.go", 0); err == nil {
    26  		t.Error("should have failed with a 0 projID")
    27  	}
    28  
    29  	if _, err := Ftok("missing_file", '+'); err != syscall.ENOENT {
    30  		t.Error("should have failed ENOENT for missing path", err)
    31  	}
    32  }