-
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.
OPCT-199: added EFS removing bindata dependency (#73)
The goal of this PR is to replace bindata dependency to Go native embed file system to handle static files used in OPCT (manifest plugins). Changes in this PR: - [blocker] remove bindata dependency, and workaround added to cover missing fixes caught by Go static checks - introduce embed filesystem to manage static data (plugin manifest templates) - improve the template handling, covering the entire manifest file, providing flexibility to apply hooks in the manifest in runtime (required for future goals like injecting dynamic scripts or manifests to run dynamic/extended tests) - increase unit tests coverage for static files and template processing - deprecate assets command (non-documented and used - plugins may not work independently, it don't need to export it to user) - expand CI jobs to keep clearly what is running, run in parallel, and keep clear the running jobs in the PRs
- Loading branch information
Showing
22 changed files
with
500 additions
and
807 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Release | ||
name: OPCT Release | ||
|
||
on: | ||
push: | ||
|
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
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,68 @@ | ||
package data | ||
|
||
import ( | ||
"embed" | ||
"testing" | ||
|
||
efs "github.com/redhat-openshift-ecosystem/provider-certification-tool/internal/assets" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
//go:embed templates/plugins | ||
var testTemplatesPluginsAll embed.FS | ||
|
||
// TestDataTemplatesPluginsManifests asserts required plugin manifests are present in EFS. | ||
func TestDataTemplatesPluginsManifests(t *testing.T) { | ||
type testCase struct { | ||
name string | ||
assert func(tc *testCase) | ||
} | ||
cases := []testCase{ | ||
{ | ||
name: "plugins-manifest-required", | ||
assert: func(tc *testCase) { | ||
want := []string{ | ||
"templates/plugins/openshift-artifacts-collector.yaml", | ||
"templates/plugins/openshift-cluster-upgrade.yaml", | ||
"templates/plugins/openshift-conformance-validated.yaml", | ||
"templates/plugins/openshift-kube-conformance.yaml", | ||
} | ||
got, err := efs.GetAllFilenames(efs.GetData(), "templates/plugins") | ||
if err != nil { | ||
t.Fatalf("failed to read efs: %v", err) | ||
} | ||
assert.Equal(t, want, got, "plugin manifest files are present") | ||
}, | ||
}, | ||
{ | ||
name: "plugins-manifest-readable", | ||
assert: func(tc *testCase) { | ||
want := true | ||
got := false | ||
manifests, err := efs.GetAllFilenames(efs.GetData(), "templates/plugins") | ||
if err != nil { | ||
t.Fatalf("failed to read efs: %v", err) | ||
} | ||
for _, m := range manifests { | ||
manifestFile, err := efs.GetData().ReadFile(m) | ||
if err != nil { | ||
t.Fatalf("unable to read manifest %s: %v", m, err) | ||
} | ||
if len(manifestFile) == 0 { | ||
t.Fatalf("empty manifest %s", m) | ||
} | ||
} | ||
got = true | ||
assert.Equal(t, want, got, "plugin manifests are readable") | ||
}, | ||
}, | ||
} | ||
|
||
efs.UpdateData(&testTemplatesPluginsAll) | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.assert(&tc) | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
package assets | ||
|
||
import ( | ||
"embed" | ||
"io/fs" | ||
) | ||
|
||
var efs *embed.FS | ||
|
||
func GetData() *embed.FS { | ||
return efs | ||
} | ||
|
||
func UpdateData(d *embed.FS) { | ||
efs = d | ||
} | ||
|
||
// GetAllFilenames return all file names from an path in embeded EFS. | ||
func GetAllFilenames(efs *embed.FS, path string) (files []string, err error) { | ||
if err := fs.WalkDir(efs, path, func(path string, d fs.DirEntry, err error) error { | ||
if d.IsDir() { | ||
return nil | ||
} | ||
|
||
files = append(files, path) | ||
|
||
return nil | ||
}); err != nil { | ||
return nil, err | ||
} | ||
|
||
return files, nil | ||
} |
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
package main | ||
|
||
import "github.com/redhat-openshift-ecosystem/provider-certification-tool/cmd" | ||
import ( | ||
"embed" | ||
|
||
cmd "github.com/redhat-openshift-ecosystem/provider-certification-tool/cmd" | ||
"github.com/redhat-openshift-ecosystem/provider-certification-tool/internal/assets" | ||
) | ||
|
||
//go:embed data/templates | ||
var vfs embed.FS | ||
|
||
func main() { | ||
assets.UpdateData(&vfs) | ||
cmd.Execute() | ||
} |
Oops, something went wrong.