github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/pkg/helper/nilinterface_test.go (about)

     1  package helper
     2  
     3  import "testing"
     4  
     5  func TestIsNil(t *testing.T) {
     6  	type args struct {
     7  		sth interface{}
     8  	}
     9  
    10  	var unassigned *args
    11  	var assigned *args = nil
    12  
    13  	tests := []struct {
    14  		name string
    15  		args args
    16  		want bool
    17  	}{{
    18  		name: "nil should be nil",
    19  		args: args{sth: nil},
    20  		want: true,
    21  	}, {
    22  		name: "unassigned should be nil",
    23  		args: args{sth: unassigned},
    24  		want: true,
    25  	}, {
    26  		name: "with nil assigned variable should be nil",
    27  		args: args{sth: assigned},
    28  		want: true,
    29  	}}
    30  	for _, tt := range tests {
    31  		t.Run(tt.name, func(t *testing.T) {
    32  			if got := IsNil(tt.args.sth); got != tt.want {
    33  				t.Errorf("IsNil() = %v, want %v", got, tt.want)
    34  			}
    35  		})
    36  	}
    37  }