Skip to content

Commit

Permalink
feat: add more test case to validator (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Jul 2, 2024
1 parent 8d0082a commit b0b2c3b
Show file tree
Hide file tree
Showing 3 changed files with 338 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"fmt"
"os"

"github.com/IceWhaleTech/CasaOS-AppManagement/service"
"github.com/IceWhaleTech/CasaOS-AppManagement/cmd/validator/pkg"
"github.com/IceWhaleTech/CasaOS-Common/utils/file"
utils_logger "github.com/IceWhaleTech/CasaOS-Common/utils/logger"
)

var logger = NewLogger()

func main() {

utils_logger.LogInitConsoleOnly()

if len(os.Args) < 1 {
Expand All @@ -29,7 +28,7 @@ func main() {

composeFileContent := file.ReadFullFile(dockerComposeFilePath)

_, err := service.NewComposeAppFromYAML(composeFileContent, false, false)
err := pkg.VaildDockerCompose(composeFileContent)
if err != nil {
logger.Error("failed to parse docker-compose file %s", err.Error())
os.Exit(1)
Expand Down
31 changes: 31 additions & 0 deletions cmd/validator/pkg/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package pkg

import (
"github.com/IceWhaleTech/CasaOS-AppManagement/codegen"
"github.com/IceWhaleTech/CasaOS-AppManagement/common"
"github.com/IceWhaleTech/CasaOS-AppManagement/service"
"github.com/compose-spec/compose-go/loader"
)

func VaildDockerCompose(yaml []byte) (err error) {
err = nil
// recover
defer func() {
if r := recover(); r != nil {
err = r.(error)
}
}()
docker, err := service.NewComposeAppFromYAML(yaml, false, false)

ex, ok := docker.Extensions[common.ComposeExtensionNameXCasaOS]
if !ok {
return service.ErrComposeExtensionNameXCasaOSNotFound
}

var storeInfo codegen.ComposeAppStoreInfo
if err = loader.Transform(ex, &storeInfo); err != nil {
return
}

return
}
Loading

0 comments on commit b0b2c3b

Please sign in to comment.