github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/dummyidm_test.go (about)

     1  //
     2  //  Copyright 2020 The AVFS authors
     3  //
     4  //  Licensed under the Apache License, Version 2.0 (the "License");
     5  //  you may not use this file except in compliance with the License.
     6  //  You may obtain a copy of the License at
     7  //
     8  //  	http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  //  Unless required by applicable law or agreed to in writing, software
    11  //  distributed under the License is distributed on an "AS IS" BASIS,
    12  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  //  See the License for the specific language governing permissions and
    14  //  limitations under the License.
    15  //
    16  
    17  //go:build !avfs_race
    18  
    19  package avfs_test
    20  
    21  import (
    22  	"testing"
    23  
    24  	"github.com/avfs/avfs"
    25  	"github.com/avfs/avfs/test"
    26  )
    27  
    28  var (
    29  	// Tests that avfs.DummyIdm implements avfs.IdentityMgr interface.
    30  	_ avfs.IdentityMgr = &avfs.DummyIdm{}
    31  
    32  	// Tests that avfs.DummyUser struct implements avfs.UserReader interface.
    33  	_ avfs.UserReader = &avfs.DummyUser{}
    34  
    35  	// Tests that avfs.DummyGroup struct implements avfs.GroupReader interface.
    36  	_ avfs.GroupReader = &avfs.DummyGroup{}
    37  )
    38  
    39  func TestDummyIdm(t *testing.T) {
    40  	idm := avfs.NewDummyIdm()
    41  
    42  	ts := test.NewSuiteIdm(t, idm)
    43  	ts.TestIdmAll(t)
    44  }
    45  
    46  func TestDummyIdmFeatures(t *testing.T) {
    47  	idm := avfs.NewDummyIdm()
    48  
    49  	if idm.Features() != 0 {
    50  		t.Errorf("Features : want Features to be 0, got %d", idm.Features())
    51  	}
    52  }
    53  
    54  func TestNewGroup(t *testing.T) {
    55  	const (
    56  		groupName = "aGroup"
    57  		gid       = 1
    58  	)
    59  
    60  	aGroup := avfs.NewGroup(groupName, gid)
    61  	if aGroup.Name() != groupName {
    62  		t.Errorf("want group to be %s, got %s", groupName, aGroup.Name())
    63  	}
    64  
    65  	if aGroup.Gid() != gid {
    66  		t.Errorf("want group id to be %d, got %d", gid, aGroup.Gid())
    67  	}
    68  }
    69  
    70  func TestNewUser(t *testing.T) {
    71  	const (
    72  		userName = "aUser"
    73  		uid      = 1
    74  		gid      = 2
    75  	)
    76  
    77  	aUser := avfs.NewUser(userName, uid, gid)
    78  	if aUser.Name() != userName {
    79  		t.Errorf("want user to be %s, got %s", userName, aUser.Name())
    80  	}
    81  
    82  	if aUser.Gid() != gid {
    83  		t.Errorf("want group id to be %d, got %d", gid, aUser.Gid())
    84  	}
    85  
    86  	if aUser.Uid() != uid {
    87  		t.Errorf("want user id to be %d, got %d", uid, aUser.Uid())
    88  	}
    89  }