feat: change interface from ID()/Release() to Distro() with both
This commit is contained in:
		| @@ -29,18 +29,14 @@ type CentOS struct { | ||||
| 	container string | ||||
| } | ||||
|  | ||||
| func (centos CentOS) ID() distro.ID { | ||||
| 	return distro.CentOS | ||||
| } | ||||
|  | ||||
| func (centos CentOS) Release() string { | ||||
| 	return centos.release | ||||
| } | ||||
|  | ||||
| func (centos CentOS) Equal(d distro.Distro) bool { | ||||
| 	return centos.release == d.Release && distro.CentOS == d.ID | ||||
| } | ||||
|  | ||||
| func (centos CentOS) Distro() distro.Distro { | ||||
| 	return distro.Distro{ID: distro.CentOS, Release: centos.release} | ||||
| } | ||||
|  | ||||
| func (centos CentOS) Packages() (pkgs []string, err error) { | ||||
| 	c, err := container.New(centos.container) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -13,8 +13,6 @@ func TestCentOS(t *testing.T) { | ||||
|  | ||||
| 	u := CentOS{release: "7", container: "out_of_tree_centos_7"} | ||||
|  | ||||
| 	assert.Equal(u.ID(), distro.CentOS) | ||||
| 	assert.Equal(u.Release(), "7") | ||||
|  | ||||
| 	assert.True(u.Equal(distro.Distro{Release: "7", ID: distro.CentOS})) | ||||
|  | ||||
|   | ||||
| @@ -43,14 +43,6 @@ type Debian struct { | ||||
| 	container string | ||||
| } | ||||
|  | ||||
| func (d Debian) ID() distro.ID { | ||||
| 	return distro.Debian | ||||
| } | ||||
|  | ||||
| func (d Debian) Release() string { | ||||
| 	return d.release.String() | ||||
| } | ||||
|  | ||||
| func (d Debian) Equal(dd distro.Distro) bool { | ||||
| 	if dd.ID != distro.Debian { | ||||
| 		return false | ||||
| @@ -59,6 +51,10 @@ func (d Debian) Equal(dd distro.Distro) bool { | ||||
| 	return ReleaseFromString(dd.Release) == d.release | ||||
| } | ||||
|  | ||||
| func (d Debian) Distro() distro.Distro { | ||||
| 	return distro.Distro{distro.Debian, d.release.String()} | ||||
| } | ||||
|  | ||||
| func (d Debian) Packages() (packages []string, err error) { | ||||
| 	c, err := container.New(d.container) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -48,8 +48,6 @@ func TestDebian(t *testing.T) { | ||||
|  | ||||
| 	u := Debian{release: Wheezy, container: "out_of_tree_debian_7"} | ||||
|  | ||||
| 	assert.Equal(u.ID(), distro.Debian) | ||||
| 	assert.Equal(u.Release(), "wheezy") | ||||
|  | ||||
| 	assert.True(u.Equal(distro.Distro{Release: "wheezy", ID: distro.Debian})) | ||||
|  | ||||
|   | ||||
| @@ -8,8 +8,7 @@ var mu sync.Mutex | ||||
| var distros []distribution | ||||
|  | ||||
| type distribution interface { | ||||
| 	ID() ID | ||||
| 	Release() string | ||||
| 	Distro() Distro | ||||
| 	Equal(Distro) bool | ||||
| 	Packages() (packages []string, err error) | ||||
| } | ||||
| @@ -22,16 +21,9 @@ func Register(d distribution) { | ||||
| } | ||||
|  | ||||
| func List() (dds []Distro) { | ||||
| 	mu.Lock() | ||||
| 	defer mu.Unlock() | ||||
|  | ||||
| 	for _, dd := range distros { | ||||
| 		dds = append(dds, Distro{ | ||||
| 			ID:      dd.ID(), | ||||
| 			Release: dd.Release(), | ||||
| 		}) | ||||
| 		dds = append(dds, dd.Distro()) | ||||
| 	} | ||||
|  | ||||
| 	return | ||||
| } | ||||
|  | ||||
| @@ -42,7 +34,7 @@ type Distro struct { | ||||
|  | ||||
| func (d Distro) Packages() (packages []string, err error) { | ||||
| 	for _, dd := range distros { | ||||
| 		if d.ID != None && d.ID != dd.ID() { | ||||
| 		if d.ID != None && d.ID != dd.Distro().ID { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -29,18 +29,14 @@ type OracleLinux struct { | ||||
| 	container string | ||||
| } | ||||
|  | ||||
| func (ol OracleLinux) ID() distro.ID { | ||||
| 	return distro.OracleLinux | ||||
| } | ||||
|  | ||||
| func (ol OracleLinux) Release() string { | ||||
| 	return ol.release | ||||
| } | ||||
|  | ||||
| func (ol OracleLinux) Equal(d distro.Distro) bool { | ||||
| 	return ol.release == d.Release && distro.OracleLinux == d.ID | ||||
| } | ||||
|  | ||||
| func (ol OracleLinux) Distro() distro.Distro { | ||||
| 	return distro.Distro{ID: distro.OracleLinux, Release: ol.release} | ||||
| } | ||||
|  | ||||
| func (ol OracleLinux) Packages() (pkgs []string, err error) { | ||||
| 	c, err := container.New(ol.container) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -13,8 +13,6 @@ func TestOracleLinux(t *testing.T) { | ||||
|  | ||||
| 	u := OracleLinux{release: "9", container: "out_of_tree_oraclelinux_9"} | ||||
|  | ||||
| 	assert.Equal(u.ID(), distro.OracleLinux) | ||||
| 	assert.Equal(u.Release(), "9") | ||||
|  | ||||
| 	assert.True(u.Equal(distro.Distro{Release: "9", ID: distro.OracleLinux})) | ||||
|  | ||||
|   | ||||
| @@ -35,18 +35,14 @@ type Ubuntu struct { | ||||
| 	container string | ||||
| } | ||||
|  | ||||
| func (u Ubuntu) ID() distro.ID { | ||||
| 	return distro.Ubuntu | ||||
| } | ||||
|  | ||||
| func (u Ubuntu) Release() string { | ||||
| 	return u.release | ||||
| } | ||||
|  | ||||
| func (u Ubuntu) Equal(d distro.Distro) bool { | ||||
| 	return u.release == d.Release && distro.Ubuntu == d.ID | ||||
| } | ||||
|  | ||||
| func (u Ubuntu) Distro() distro.Distro { | ||||
| 	return distro.Distro{ID: distro.Ubuntu, Release: u.release} | ||||
| } | ||||
|  | ||||
| func (u Ubuntu) Packages() (pkgs []string, err error) { | ||||
| 	c, err := container.New(u.container) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -13,9 +13,6 @@ func TestUbuntu(t *testing.T) { | ||||
|  | ||||
| 	u := Ubuntu{release: "22.04", container: "out_of_tree_ubuntu_22__04"} | ||||
|  | ||||
| 	assert.Equal(u.ID(), distro.Ubuntu) | ||||
| 	assert.Equal(u.Release(), "22.04") | ||||
|  | ||||
| 	assert.True(u.Equal(distro.Distro{Release: "22.04", ID: distro.Ubuntu})) | ||||
|  | ||||
| 	assert.NotEmpty(u.Packages()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user