-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test case and the workflow 'Publish Specified Packages'
Signed-off-by: zongz <[email protected]>
- Loading branch information
Showing
7 changed files
with
133 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test Generate Metadata | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.21 | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get dependencies | ||
run: go get -v -t -d ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
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
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,56 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"gopkg.in/yaml.v2" | ||
"gotest.tools/assert" | ||
"kcl-lang.io/kpm/pkg/utils" | ||
) | ||
|
||
func TestUpdateReadmeAndMetadata(t *testing.T) { | ||
pwd, err := os.Getwd() | ||
assert.Equal(t, nil, err) | ||
testDir := filepath.Join(pwd, "helloworld") | ||
modPath := filepath.Join(testDir, "kcl.mod") | ||
ahPath := filepath.Join(testDir, "0.1.0", "artifacthub-pkg.yaml") | ||
|
||
if utils.DirExists(ahPath) { | ||
err = os.Remove(ahPath) | ||
assert.Equal(t, nil, err) | ||
} | ||
assert.Equal(t, false, utils.DirExists(ahPath)) | ||
err = UpdateReadmeAndMetadata(modPath) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, true, utils.DirExists(ahPath)) | ||
|
||
buf, err := os.ReadFile(ahPath) | ||
assert.Equal(t, nil, err) | ||
|
||
var metadata Metadata | ||
err = yaml.Unmarshal(buf, &metadata) | ||
assert.Equal(t, nil, err) | ||
|
||
assert.Equal(t, "helloworld", metadata.Name) | ||
assert.Equal(t, "helloworld", metadata.DisplayName) | ||
assert.Equal(t, "0.1.0", metadata.Version) | ||
assert.Equal(t, "This is a KCL package", metadata.Description) | ||
assert.Equal(t, len(metadata.Links), 2) | ||
assert.Equal(t, metadata.Links[0].Name, "KCL homepage") | ||
assert.Equal(t, metadata.Links[0].URL, "https://kcl-lang.io/") | ||
assert.Equal(t, metadata.Links[1].Name, "KCL repo") | ||
assert.Equal(t, metadata.Links[1].URL, "https://github.com/kcl-lang/kcl") | ||
assert.Equal(t, metadata.Provider.Name, "kcl-lang.io") | ||
assert.Equal(t, len(metadata.Maintainers), 1) | ||
assert.Equal(t, metadata.Maintainers[0].Name, "kcl-lang.io") | ||
assert.Equal(t, metadata.Maintainers[0].Email, "[email protected]") | ||
|
||
installationTemplate, err := os.ReadFile("./templates/install.md") | ||
assert.Equal(t, nil, err) | ||
installDoc := strings.Replace(string(installationTemplate), MdFlagPackageName, "helloworld", -1) | ||
installDoc = strings.Replace(string(installDoc), MdFlagPackageTag, "0.1.0", -1) | ||
assert.Equal(t, installDoc, metadata.Install) | ||
} |