-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change packages list command output to satisfy NEVRA format (#474)
- Loading branch information
1 parent
87ace58
commit 65f1873
Showing
3 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright (c) 2019 Snowflake Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
package domain | ||
|
||
import ( | ||
"fmt" | ||
pb "github.com/Snowflake-Labs/sansshell/services/packages" | ||
) | ||
|
||
// ToNevraStr convert [pb.PackageInfo] into NEVRA formated string. | ||
// It usually used to install/update packages or compare their version and builds. | ||
func ToNevraStr(pkg *pb.PackageInfo) string { | ||
return fmt.Sprintf("%s-%d:%s-%s.%s", pkg.Name, pkg.Epoch, pkg.Version, pkg.Release, pkg.Architecture) | ||
} |
58 changes: 58 additions & 0 deletions
58
services/packages/client/domain/package.domain-service_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Copyright (c) 2019 Snowflake Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
package domain | ||
|
||
import ( | ||
pb "github.com/Snowflake-Labs/sansshell/services/packages" | ||
"testing" | ||
) | ||
|
||
func TestToNevraStr(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input *pb.PackageInfo | ||
expected string | ||
}{ | ||
{ | ||
name: "It should convert package info to NEVRA string", | ||
input: &pb.PackageInfo{Name: "test", Epoch: 1, Version: "1.0.0", Release: "1", Architecture: "x86_64"}, | ||
expected: "test-1:1.0.0-1.x86_64", | ||
}, | ||
{ | ||
name: "It should convert package info to NEVRA string, in case of epoch is 0", | ||
input: &pb.PackageInfo{Name: "test", Epoch: 0, Version: "1.0.0", Release: "1", Architecture: "x86_64"}, | ||
expected: "test-0:1.0.0-1.x86_64", | ||
}, | ||
{ | ||
name: "It should convert package info to NEVRA string, in case of version is not in XX.XX.XX format", | ||
input: &pb.PackageInfo{Name: "test", Epoch: 0, Version: "1.10.22_rc-2", Release: "1", Architecture: "x86_64"}, | ||
expected: "test-0:1.10.22_rc-2-1.x86_64", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
// ACT | ||
result := ToNevraStr(test.input) | ||
|
||
// ASSERT | ||
if result != test.expected { | ||
t.Errorf("Expected %s, but provided %s", test.expected, result) | ||
} | ||
}) | ||
} | ||
} |