github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/orbiter/kinds/providers/cs/machinesservice_test.go (about)

     1  package cs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/cloudscale-ch/cloudscale-go-sdk"
     7  )
     8  
     9  type ifType string
    10  
    11  var (
    12  	private ifType = "private"
    13  	public  ifType = "public"
    14  )
    15  
    16  func Test_createdIPs(t *testing.T) {
    17  
    18  	newInterface := func(t ifType) cloudscale.Interface {
    19  		return cloudscale.Interface{
    20  			Type:    string(t),
    21  			Network: cloudscale.NetworkStub{},
    22  			Addresses: []cloudscale.Address{{
    23  				Address: string(t),
    24  			}},
    25  		}
    26  	}
    27  
    28  	type args struct {
    29  		interfaces []cloudscale.Interface
    30  		oneoff     bool
    31  	}
    32  	tests := []struct {
    33  		name  string
    34  		args  args
    35  		want  ifType
    36  		want1 ifType
    37  	}{{
    38  		name: "sshing is done against public interface when in oneoff mode, for ORBITER, the private ip is relevant",
    39  		args: args{
    40  			interfaces: []cloudscale.Interface{
    41  				newInterface(private),
    42  				newInterface(public),
    43  			},
    44  			oneoff: true,
    45  		},
    46  		want:  private,
    47  		want1: public,
    48  	}, {
    49  		name: "sshing is done against private interface when in recurring mode, for ORBITER, the private ip is relevant",
    50  		args: args{
    51  			interfaces: []cloudscale.Interface{
    52  				newInterface(private),
    53  				newInterface(public),
    54  			},
    55  			oneoff: false,
    56  		},
    57  		want:  private,
    58  		want1: private,
    59  	}}
    60  	for _, tt := range tests {
    61  		t.Run(tt.name, func(t *testing.T) {
    62  			got, got1 := createdIPs(tt.args.interfaces, tt.args.oneoff)
    63  			if got != string(tt.want) {
    64  				t.Errorf("createdIPs() got = %v, want %v", got, tt.want)
    65  			}
    66  			if got1 != string(tt.want1) {
    67  				t.Errorf("createdIPs() got1 = %v, want %v", got1, tt.want1)
    68  			}
    69  		})
    70  	}
    71  }