...

Source file src/github.com/coreos/go-systemd/v22/internal/dlopen/dlopen_test.go

Documentation: github.com/coreos/go-systemd/v22/internal/dlopen

     1  // Copyright 2015 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package dlopen
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  )
    21  
    22  func checkFailure(shouldSucceed bool, err error) (rErr error) {
    23  	switch {
    24  	case err != nil && shouldSucceed:
    25  		rErr = fmt.Errorf("expected test to succeed, failed unexpectedly: %v", err)
    26  	case err == nil && !shouldSucceed:
    27  		rErr = fmt.Errorf("expected test to fail, succeeded unexpectedly")
    28  	}
    29  
    30  	return
    31  }
    32  
    33  func TestDlopen(t *testing.T) {
    34  	tests := []struct {
    35  		libs          []string
    36  		shouldSucceed bool
    37  	}{
    38  		{
    39  			libs: []string{
    40  				"libc.so.6",
    41  				"libc.so",
    42  			},
    43  			shouldSucceed: true,
    44  		},
    45  		{
    46  			libs: []string{
    47  				"libstrange.so",
    48  			},
    49  			shouldSucceed: false,
    50  		},
    51  	}
    52  
    53  	for i, tt := range tests {
    54  		expLen := 4
    55  		len, err := strlen(tt.libs, "test")
    56  		if checkFailure(tt.shouldSucceed, err) != nil {
    57  			t.Errorf("case %d: %v", i, err)
    58  		}
    59  
    60  		if tt.shouldSucceed && len != expLen {
    61  			t.Errorf("case %d: expected length %d, got %d", i, expLen, len)
    62  		}
    63  	}
    64  }
    65  

View as plain text