github.com/openshift/installer@v1.4.17/pkg/asset/ignition/bootstrap/registries_test.go (about)

     1  package bootstrap
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/openshift/installer/pkg/types"
     9  )
    10  
    11  func TestMergedMirrorSets(t *testing.T) {
    12  	tests := []struct {
    13  		name     string
    14  		input    []types.ImageDigestSource
    15  		expected []types.ImageDigestSource
    16  	}{{
    17  		input: []types.ImageDigestSource{{
    18  			Source: "a",
    19  		}, {
    20  			Source: "b",
    21  		}},
    22  		expected: []types.ImageDigestSource{{
    23  			Source: "a",
    24  		}, {
    25  			Source: "b",
    26  		}},
    27  	}, {
    28  		input: []types.ImageDigestSource{{
    29  			Source: "a",
    30  		}, {
    31  			Source: "a",
    32  		}},
    33  		expected: []types.ImageDigestSource{{
    34  			Source: "a",
    35  		}},
    36  	}, {
    37  		input: []types.ImageDigestSource{{
    38  			Source:  "a",
    39  			Mirrors: []string{"ma", "mb", "mb"},
    40  		}, {
    41  			Source:  "a",
    42  			Mirrors: []string{"mc", "mc", "md"},
    43  		}},
    44  		expected: []types.ImageDigestSource{{
    45  			Source:  "a",
    46  			Mirrors: []string{"ma", "mb", "mc", "md"},
    47  		}},
    48  	}, {
    49  		input: []types.ImageDigestSource{{
    50  			Source:  "a",
    51  			Mirrors: []string{"ma", "mb"},
    52  		}, {
    53  			Source:  "b",
    54  			Mirrors: []string{"mc", "md"},
    55  		}},
    56  		expected: []types.ImageDigestSource{{
    57  			Source:  "a",
    58  			Mirrors: []string{"ma", "mb"},
    59  		}, {
    60  			Source:  "b",
    61  			Mirrors: []string{"mc", "md"},
    62  		}},
    63  	}, {
    64  		input: []types.ImageDigestSource{{
    65  			Source:  "a",
    66  			Mirrors: []string{"ma", "mb"},
    67  		}, {
    68  			Source:  "a",
    69  			Mirrors: []string{"ma", "md"},
    70  		}},
    71  		expected: []types.ImageDigestSource{{
    72  			Source:  "a",
    73  			Mirrors: []string{"ma", "mb", "md"},
    74  		}},
    75  	}, {
    76  		input: []types.ImageDigestSource{{
    77  			Source:  "a",
    78  			Mirrors: []string{"ma", "mb"},
    79  		}, {
    80  			Source:  "a",
    81  			Mirrors: []string{"md", "ma"},
    82  		}},
    83  		expected: []types.ImageDigestSource{{
    84  			Source:  "a",
    85  			Mirrors: []string{"ma", "mb", "md"},
    86  		}},
    87  	}, {
    88  		input: []types.ImageDigestSource{{
    89  			Source:  "a",
    90  			Mirrors: []string{"ma", "mb"},
    91  		}, {
    92  			Source:  "a",
    93  			Mirrors: []string{"md", "ma"},
    94  		}, {
    95  			Source:  "a",
    96  			Mirrors: []string{"me", "mb"},
    97  		}},
    98  		expected: []types.ImageDigestSource{{
    99  			Source:  "a",
   100  			Mirrors: []string{"ma", "mb", "md", "me"},
   101  		}},
   102  	}, {
   103  		input: []types.ImageDigestSource{{
   104  			Source:  "a",
   105  			Mirrors: []string{"ma"},
   106  		}, {
   107  			Source:  "b",
   108  			Mirrors: []string{"md", "mc"},
   109  		}, {
   110  			Source:  "a",
   111  			Mirrors: []string{"mb", "ma"},
   112  		}},
   113  		expected: []types.ImageDigestSource{{
   114  			Source:  "a",
   115  			Mirrors: []string{"ma", "mb"},
   116  		}, {
   117  			Source:  "b",
   118  			Mirrors: []string{"md", "mc"},
   119  		}},
   120  	}}
   121  	for _, test := range tests {
   122  		t.Run(test.name, func(t *testing.T) {
   123  			assert.Equal(t, test.expected, MergedMirrorSets(test.input))
   124  		})
   125  	}
   126  }
   127  
   128  func TestContentSourceToDigestMirror(t *testing.T) {
   129  	tests := []struct {
   130  		name     string
   131  		input    []types.ImageContentSource
   132  		expected []types.ImageDigestSource
   133  	}{{
   134  		input: []types.ImageContentSource{{
   135  			Source:  "a",
   136  			Mirrors: []string{"ma", "mb", "mb"},
   137  		}, {
   138  			Source:  "a",
   139  			Mirrors: []string{"mc", "mc", "md"},
   140  		}},
   141  		expected: []types.ImageDigestSource{{
   142  			Source:  "a",
   143  			Mirrors: []string{"ma", "mb", "mb"},
   144  		}, {
   145  			Source:  "a",
   146  			Mirrors: []string{"mc", "mc", "md"},
   147  		}},
   148  	}}
   149  	for _, test := range tests {
   150  		t.Run(test.name, func(t *testing.T) {
   151  			assert.Equal(t, test.expected, ContentSourceToDigestMirror(test.input))
   152  		})
   153  	}
   154  }