Skip to content

Commit

Permalink
style: change job template
Browse files Browse the repository at this point in the history
  • Loading branch information
ViolaPioggia committed Jul 7, 2024
1 parent 785d8c1 commit 877654b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
11 changes: 10 additions & 1 deletion pkg/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"strings"
"text/template"

"github.com/cloudwego/cwgo/meta"

"github.com/cloudwego/cwgo/config"
"github.com/cloudwego/cwgo/pkg/common/utils"
"github.com/cloudwego/cwgo/pkg/consts"
Expand Down Expand Up @@ -324,7 +326,14 @@ func generateJobFile(GoModule, PackagePrefix string, jobNames []string, outDir s
}

var jobFileContent bytes.Buffer
err = tmpl.Execute(&jobFileContent, jobsInfo.JobInfos[0])
data := struct {
PackagePrefix string
Version string
}{
PackagePrefix: PackagePrefix,
Version: meta.Version,
}
err = tmpl.Execute(&jobFileContent, data)
if err != nil {
return err
}
Expand Down
19 changes: 17 additions & 2 deletions pkg/job/job_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package job

import (
Expand Down Expand Up @@ -208,7 +224,7 @@ func TestJobWithoutGoModInGOPATH(t *testing.T) {

// Create a directory structure under GOPATH/src
projectPath := filepath.Join(tmpGopath, "src", "github.com", "cloudwego", "cwgo")
if err := os.MkdirAll(projectPath, 0755); err != nil {
if err := os.MkdirAll(projectPath, 0o755); err != nil {
t.Fatalf("Failed to create project directory: %v", err)
}

Expand Down Expand Up @@ -241,5 +257,4 @@ func TestJobWithoutGoModInGOPATH(t *testing.T) {
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() != 0 {
t.Logf("Expected process to exit with status 0, got %d. Output: %s", exitErr.ExitCode(), output)
}

}
2 changes: 1 addition & 1 deletion pkg/job/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Run() {
}
`

const jobMainTemplate = `// Code generated by cwgo. DO NOT EDIT.
const jobMainTemplate = `// Code generated by cwgo ({{.Version}}). DO NOT EDIT.
package main
import (
Expand Down

0 comments on commit 877654b

Please sign in to comment.