|
| 1 | +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 2 | +// or more contributor license agreements. Licensed under the Elastic License 2.0; |
| 3 | +// you may not use this file except in compliance with the Elastic License 2.0. |
| 4 | + |
| 5 | +package artifact |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | + |
| 12 | + agtversion "github.com/elastic/elastic-agent/pkg/version" |
| 13 | +) |
| 14 | + |
| 15 | +func TestGetArtifactName(t *testing.T) { |
| 16 | + version, err := agtversion.ParseVersion("9.1.0") |
| 17 | + require.NoError(t, err) |
| 18 | + |
| 19 | + tests := map[string]struct { |
| 20 | + a Artifact |
| 21 | + version agtversion.ParsedSemVer |
| 22 | + arch string |
| 23 | + expectedName string |
| 24 | + }{ |
| 25 | + "no_fips_arm64": { |
| 26 | + a: Artifact{Cmd: "elastic-agent"}, |
| 27 | + version: *version, |
| 28 | + arch: "arm64", |
| 29 | + expectedName: "elastic-agent-9.1.0-linux-arm64.tar.gz", |
| 30 | + }, |
| 31 | + "fips_x86": { |
| 32 | + a: Artifact{Cmd: "elastic-agent-fips"}, |
| 33 | + version: *version, |
| 34 | + arch: "32", |
| 35 | + expectedName: "elastic-agent-fips-9.1.0-linux-x86.tar.gz", |
| 36 | + }, |
| 37 | + "fips_x86_64": { |
| 38 | + a: Artifact{Cmd: "elastic-agent-fips"}, |
| 39 | + version: *version, |
| 40 | + arch: "64", |
| 41 | + expectedName: "elastic-agent-fips-9.1.0-linux-x86_64.tar.gz", |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + for name, test := range tests { |
| 46 | + t.Run(name, func(t *testing.T) { |
| 47 | + artifactName, err := GetArtifactName(test.a, test.version, "linux", test.arch) |
| 48 | + require.NoError(t, err) |
| 49 | + require.Equal(t, test.expectedName, artifactName) |
| 50 | + }) |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments