github.com/lalkh/containerd@v1.4.3/task_opts_unix_test.go (about)

     1  // +build !windows
     2  
     3  /*
     4     Copyright The containerd Authors.
     5  
     6     Licensed under the Apache License, Version 2.0 (the "License");
     7     you may not use this file except in compliance with the License.
     8     You may obtain a copy of the License at
     9  
    10         http://www.apache.org/licenses/LICENSE-2.0
    11  
    12     Unless required by applicable law or agreed to in writing, software
    13     distributed under the License is distributed on an "AS IS" BASIS,
    14     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15     See the License for the specific language governing permissions and
    16     limitations under the License.
    17  */
    18  
    19  package containerd
    20  
    21  import (
    22  	"context"
    23  	"testing"
    24  
    25  	"github.com/containerd/containerd/runtime/linux/runctypes"
    26  )
    27  
    28  func TestWithNoNewKeyringAddsNoNewKeyringToOptions(t *testing.T) {
    29  	var taskInfo TaskInfo
    30  	var ctx context.Context
    31  	var client Client
    32  
    33  	err := WithNoNewKeyring(ctx, &client, &taskInfo)
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  
    38  	opts := taskInfo.Options.(*runctypes.CreateOptions)
    39  
    40  	if !opts.NoNewKeyring {
    41  		t.Fatal("NoNewKeyring set on WithNoNewKeyring")
    42  	}
    43  
    44  }
    45  
    46  func TestWithNoNewKeyringDoesNotOverwriteOtherOptions(t *testing.T) {
    47  	var taskInfo TaskInfo
    48  	var ctx context.Context
    49  	var client Client
    50  
    51  	taskInfo.Options = &runctypes.CreateOptions{NoPivotRoot: true}
    52  
    53  	err := WithNoNewKeyring(ctx, &client, &taskInfo)
    54  	if err != nil {
    55  		t.Fatal(err)
    56  	}
    57  
    58  	opts := taskInfo.Options.(*runctypes.CreateOptions)
    59  
    60  	if !opts.NoPivotRoot {
    61  		t.Fatal("WithNoNewKeyring overwrote other options")
    62  	}
    63  }