|
4 | 4 | "reflect"
|
5 | 5 | "testing"
|
6 | 6 |
|
7 |
| - "github.com/k0kubun/pp" |
8 |
| - |
9 | 7 | "github.com/future-architect/vuls/config"
|
10 | 8 | "github.com/future-architect/vuls/constant"
|
11 | 9 | "github.com/future-architect/vuls/logging"
|
@@ -596,44 +594,97 @@ func Test_redhatBase_parseInstalledPackagesLineFromRepoquery(t *testing.T) {
|
596 | 594 | }
|
597 | 595 | }
|
598 | 596 |
|
599 |
| -func TestParseYumCheckUpdateLine(t *testing.T) { |
600 |
| - r := newCentOS(config.ServerInfo{}) |
601 |
| - r.Distro = config.Distro{Family: "centos"} |
602 |
| - var tests = []struct { |
603 |
| - in string |
604 |
| - out models.Package |
| 597 | +func Test_redhatBase_parseUpdatablePacksLine(t *testing.T) { |
| 598 | + type fields struct { |
| 599 | + base base |
| 600 | + sudo rootPriv |
| 601 | + } |
| 602 | + type args struct { |
| 603 | + line string |
| 604 | + } |
| 605 | + tests := []struct { |
| 606 | + name string |
| 607 | + fields fields |
| 608 | + args args |
| 609 | + want models.Package |
| 610 | + wantErr bool |
605 | 611 | }{
|
606 | 612 | {
|
607 |
| - "zlib 0 1.2.7 17.el7 rhui-REGION-rhel-server-releases", |
608 |
| - models.Package{ |
| 613 | + name: `centos 7.0: "zlib" "0" "1.2.7" "17.el7" "rhui-REGION-rhel-server-releases"`, |
| 614 | + fields: fields{ |
| 615 | + base: base{ |
| 616 | + Distro: config.Distro{ |
| 617 | + Family: constant.CentOS, |
| 618 | + Release: "7.0", |
| 619 | + }, |
| 620 | + }, |
| 621 | + }, |
| 622 | + args: args{ |
| 623 | + line: `"zlib" "0" "1.2.7" "17.el7" "rhui-REGION-rhel-server-releases"`, |
| 624 | + }, |
| 625 | + want: models.Package{ |
609 | 626 | Name: "zlib",
|
610 | 627 | NewVersion: "1.2.7",
|
611 | 628 | NewRelease: "17.el7",
|
612 | 629 | Repository: "rhui-REGION-rhel-server-releases",
|
613 | 630 | },
|
614 | 631 | },
|
615 | 632 | {
|
616 |
| - "shadow-utils 2 4.1.5.1 24.el7 rhui-REGION-rhel-server-releases", |
617 |
| - models.Package{ |
| 633 | + name: `centos 7.0: "shadow-utils" "2" "4.1.5.1 24.el7" "rhui-REGION-rhel-server-releases"`, |
| 634 | + fields: fields{ |
| 635 | + base: base{ |
| 636 | + Distro: config.Distro{ |
| 637 | + Family: constant.CentOS, |
| 638 | + Release: "7.0", |
| 639 | + }, |
| 640 | + }, |
| 641 | + }, |
| 642 | + args: args{ |
| 643 | + line: `"shadow-utils" "2" "4.1.5.1" "24.el7" "rhui-REGION-rhel-server-releases"`, |
| 644 | + }, |
| 645 | + want: models.Package{ |
618 | 646 | Name: "shadow-utils",
|
619 | 647 | NewVersion: "2:4.1.5.1",
|
620 | 648 | NewRelease: "24.el7",
|
621 | 649 | Repository: "rhui-REGION-rhel-server-releases",
|
622 | 650 | },
|
623 | 651 | },
|
| 652 | + { |
| 653 | + name: `amazon 2023: Is this ok [y/N]: "dnf" "0" "4.14.0" "1.amzn2023.0.6" "amazonlinux"`, |
| 654 | + fields: fields{ |
| 655 | + base: base{ |
| 656 | + Distro: config.Distro{ |
| 657 | + Family: constant.Amazon, |
| 658 | + Release: "2023.7.20250512", |
| 659 | + }, |
| 660 | + }, |
| 661 | + }, |
| 662 | + args: args{ |
| 663 | + line: `Is this ok [y/N]: "dnf" "0" "4.14.0" "1.amzn2023.0.6" "amazonlinux"`, |
| 664 | + }, |
| 665 | + want: models.Package{ |
| 666 | + Name: "dnf", |
| 667 | + NewVersion: "4.14.0", |
| 668 | + NewRelease: "1.amzn2023.0.6", |
| 669 | + Repository: "amazonlinux", |
| 670 | + }, |
| 671 | + }, |
624 | 672 | }
|
625 |
| - |
626 | 673 | for _, tt := range tests {
|
627 |
| - aPack, err := r.parseUpdatablePacksLine(tt.in) |
628 |
| - if err != nil { |
629 |
| - t.Errorf("Error has occurred, err: %+v\ntt.in: %v", err, tt.in) |
630 |
| - return |
631 |
| - } |
632 |
| - if !reflect.DeepEqual(tt.out, aPack) { |
633 |
| - e := pp.Sprintf("%v", tt.out) |
634 |
| - a := pp.Sprintf("%v", aPack) |
635 |
| - t.Errorf("expected %s, actual %s", e, a) |
636 |
| - } |
| 674 | + t.Run(tt.name, func(t *testing.T) { |
| 675 | + o := &redhatBase{ |
| 676 | + base: tt.fields.base, |
| 677 | + sudo: tt.fields.sudo, |
| 678 | + } |
| 679 | + got, err := o.parseUpdatablePacksLine(tt.args.line) |
| 680 | + if (err != nil) != tt.wantErr { |
| 681 | + t.Errorf("redhatBase.parseUpdatablePacksLine() error = %v, wantErr %v", err, tt.wantErr) |
| 682 | + return |
| 683 | + } |
| 684 | + if !reflect.DeepEqual(got, tt.want) { |
| 685 | + t.Errorf("redhatBase.parseUpdatablePacksLine() = %v, want %v", got, tt.want) |
| 686 | + } |
| 687 | + }) |
637 | 688 | }
|
638 | 689 | }
|
639 | 690 |
|
@@ -672,13 +723,12 @@ func Test_redhatBase_parseUpdatablePacksLines(t *testing.T) {
|
672 | 723 | },
|
673 | 724 | },
|
674 | 725 | args: args{
|
675 |
| - stdout: `audit-libs 0 2.3.7 5.el6 base |
676 |
| -bash 0 4.1.2 33.el6_7.1 updates |
677 |
| -python-libs 0 2.6.6 64.el6 rhui-REGION-rhel-server-releases |
678 |
| -python-ordereddict 0 1.1 3.el6ev installed |
679 |
| -bind-utils 30 9.3.6 25.P1.el5_11.8 updates |
680 |
| -pytalloc 0 2.0.7 2.el6 @CentOS 6.5/6.5`, |
681 |
| - }, |
| 726 | + stdout: `"audit-libs" "0" "2.3.7" "5.el6" "base" |
| 727 | +"bash" "0" "4.1.2" "33.el6_7.1" "updates" |
| 728 | +"python-libs" "0" "2.6.6" "64.el6" "rhui-REGION-rhel-server-releases" |
| 729 | +"python-ordereddict" "0" "1.1" "3.el6ev" "installed" |
| 730 | +"bind-utils" "30" "9.3.6" "25.P1.el5_11.8" "updates" |
| 731 | +"pytalloc" "0" "2.0.7" "2.el6" "@CentOS 6.5/6.5"`}, |
682 | 732 | want: models.Packages{
|
683 | 733 | "audit-libs": {
|
684 | 734 | Name: "audit-libs",
|
@@ -735,9 +785,9 @@ pytalloc 0 2.0.7 2.el6 @CentOS 6.5/6.5`,
|
735 | 785 | },
|
736 | 786 | },
|
737 | 787 | args: args{
|
738 |
| - stdout: `bind-libs 32 9.8.2 0.37.rc1.45.amzn1 amzn-main |
739 |
| -java-1.7.0-openjdk 0 1.7.0.95 2.6.4.0.65.amzn1 amzn-main |
740 |
| -if-not-architecture 0 100 200 amzn-main`, |
| 788 | + stdout: `"bind-libs" "32" "9.8.2" "0.37.rc1.45.amzn1" "amzn-main" |
| 789 | +"java-1.7.0-openjdk" "0" "1.7.0.95" "2.6.4.0.65.amzn1" "amzn-main" |
| 790 | +"if-not-architecture" "0" "100" "200" "amzn-main"`, |
741 | 791 | },
|
742 | 792 | want: models.Packages{
|
743 | 793 | "bind-libs": {
|
|
0 commit comments