| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package internal |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func TestDistroURL(t *testing.T) { |
| 13 |
tests := []struct { |
| 14 |
input string |
| 15 |
output string |
| 16 |
}{ |
| 17 |
{ |
| 18 |
input: "core", |
| 19 |
output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol", |
| 20 |
}, |
| 21 |
{ |
| 22 |
input: "contrib", |
| 23 |
output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib", |
| 24 |
}, |
| 25 |
{ |
| 26 |
input: "k8s", |
| 27 |
output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s", |
| 28 |
}, |
| 29 |
{ |
| 30 |
input: "otlp", |
| 31 |
output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-otlp", |
| 32 |
}, |
| 33 |
{ |
| 34 |
input: "not_found", |
| 35 |
output: "", |
| 36 |
}, |
| 37 |
} |
| 38 |
for _, test := range tests { |
| 39 |
t.Run(test.input, func(t *testing.T) { |
| 40 |
assert.Equal(t, test.output, distroURL(test.input)) |
| 41 |
}) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func TestSortedDistributions(t *testing.T) { |
| 46 |
tests := []struct { |
| 47 |
name string |
| 48 |
s Status |
| 49 |
result []string |
| 50 |
}{ |
| 51 |
{ |
| 52 |
"all combined", |
| 53 |
Status{Distributions: []string{"arm", "contrib", "core", "foo", "bar"}}, |
| 54 |
[]string{"core", "contrib", "arm", "bar", "foo"}, |
| 55 |
}, |
| 56 |
{ |
| 57 |
"core only", |
| 58 |
Status{Distributions: []string{"core"}}, |
| 59 |
[]string{"core"}, |
| 60 |
}, |
| 61 |
{ |
| 62 |
"core and contrib only", |
| 63 |
Status{Distributions: []string{"core", "contrib"}}, |
| 64 |
[]string{"core", "contrib"}, |
| 65 |
}, |
| 66 |
{ |
| 67 |
"core and contrib reversed", |
| 68 |
Status{Distributions: []string{"contrib", "core"}}, |
| 69 |
[]string{"core", "contrib"}, |
| 70 |
}, |
| 71 |
{ |
| 72 |
"neither core nor contrib", |
| 73 |
Status{Distributions: []string{"foo", "bar"}}, |
| 74 |
[]string{"bar", "foo"}, |
| 75 |
}, |
| 76 |
{ |
| 77 |
"no core, contrib, something else", |
| 78 |
Status{Distributions: []string{"foo", "contrib", "bar"}}, |
| 79 |
[]string{"contrib", "bar", "foo"}, |
| 80 |
}, |
| 81 |
{ |
| 82 |
"core, no contrib, something else", |
| 83 |
Status{Distributions: []string{"foo", "core", "bar"}}, |
| 84 |
[]string{"core", "bar", "foo"}, |
| 85 |
}, |
| 86 |
} |
| 87 |
for _, test := range tests { |
| 88 |
t.Run(test.name, func(t *testing.T) { |
| 89 |
assert.Equal(t, test.result, test.s.SortedDistributions()) |
| 90 |
}) |
| 91 |
} |
| 92 |
} |