-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve template structure and add basic tests
- Loading branch information
Showing
14 changed files
with
724 additions
and
23 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,28 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '**/*.md' | ||
branches: | ||
- main | ||
pull_request: | ||
paths-ignore: | ||
- '**/*.md' | ||
|
||
jobs: | ||
linux-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '>=1.21' | ||
- run: go version | ||
- name: Test | ||
run: go test -v -covermode=count -coverprofile=coverage.out | ||
- name: Upload coverage | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
fail_ci_if_error: true | ||
files: coverage.out |
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,63 @@ | ||
package nixose | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func getPaths(t *testing.T) (string, string, string) { | ||
outFileName := fmt.Sprintf("%s_out.nix", t.Name()) | ||
composePath := path.Join("testdata", "docker-compose.yml") | ||
envFilePath := path.Join("testdata", "input.env") | ||
outFilePath := path.Join("testdata", outFileName) | ||
return composePath, envFilePath, outFilePath | ||
} | ||
|
||
func TestDocker(t *testing.T) { | ||
ctx := context.Background() | ||
composePath, envFilePath, outFilePath := getPaths(t) | ||
g := Generator{ | ||
Runtime: ContainerRuntimeDocker, | ||
Paths: []string{composePath}, | ||
EnvFiles: []string{envFilePath}, | ||
} | ||
c, err := g.Run(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
wantOutput, err := os.ReadFile(outFilePath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got, want := c.String(), string(wantOutput) | ||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("output diff: %s\n", diff) | ||
} | ||
} | ||
|
||
func TestPodman(t *testing.T) { | ||
ctx := context.Background() | ||
composePath, envFilePath, outFilePath := getPaths(t) | ||
g := Generator{ | ||
Runtime: ContainerRuntimePodman, | ||
Paths: []string{composePath}, | ||
EnvFiles: []string{envFilePath}, | ||
} | ||
c, err := g.Run(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
wantOutput, err := os.ReadFile(outFilePath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got, want := c.String(), string(wantOutput) | ||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("output diff: %s\n", diff) | ||
} | ||
} |
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
Oops, something went wrong.