From 86940e89624b997c76cb6221e132c0f0093fea6b Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Thu, 13 Mar 2025 16:38:36 +0300 Subject: [PATCH] tests: add TestRemoveDuplicatesSources --- assets/coverage-badge.svg | 4 +-- pkg/build/utils_internal_test.go | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 pkg/build/utils_internal_test.go diff --git a/assets/coverage-badge.svg b/assets/coverage-badge.svg index ffdf7ae..4257307 100644 --- a/assets/coverage-badge.svg +++ b/assets/coverage-badge.svg @@ -11,7 +11,7 @@ coverage coverage - 19.4% - 19.4% + 19.8% + 19.8% diff --git a/pkg/build/utils_internal_test.go b/pkg/build/utils_internal_test.go new file mode 100644 index 0000000..a12ca64 --- /dev/null +++ b/pkg/build/utils_internal_test.go @@ -0,0 +1,47 @@ +// ALR - Any Linux Repository +// Copyright (C) 2025 Евгений Храмов +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package build + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRemoveDuplicatesSources(t *testing.T) { + type testCase struct { + Name string + Sources []string + Checksums []string + NewSources []string + NewChecksums []string + } + + for _, tc := range []testCase{{ + Name: "prefer non-skip values", + Sources: []string{"a", "b", "c", "a"}, + Checksums: []string{"skip", "skip", "skip", "1"}, + NewSources: []string{"a", "b", "c"}, + NewChecksums: []string{"1", "skip", "skip"}, + }} { + t.Run(tc.Name, func(t *testing.T) { + s, c := removeDuplicatesSources(tc.Sources, tc.Checksums) + assert.Equal(t, s, tc.NewSources) + assert.Equal(t, c, tc.NewChecksums) + }) + } +}