Skip to content

Commit

Permalink
Added template unit tests for docs and licenses
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Rickard <[email protected]>
  • Loading branch information
jeremyrickard authored and cpuguy83 committed May 28, 2024
1 parent 5318c83 commit ebf08e6
Showing 1 changed file with 108 additions and 10 deletions.
118 changes: 108 additions & 10 deletions frontend/rpm/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,116 @@ func TestTemplateSources(t *testing.T) {
}

func TestTemplate_Artifacts(t *testing.T) {

w := &specWrapper{Spec: &dalec.Spec{
Artifacts: dalec.Artifacts{
SystemdUnits: map[string]dalec.SystemdUnitConfig{
"test.service": {},
t.Run("test systemd unit postun", func(t *testing.T) {
t.Parallel()
w := &specWrapper{Spec: &dalec.Spec{
Artifacts: dalec.Artifacts{
SystemdUnits: map[string]dalec.SystemdUnitConfig{
"test.service": {},
},
},
},
}}
}}

got := w.PostUn().String()
want := `%postun
got := w.PostUn().String()
want := `%postun
%systemd_postun test.service
`
assert.Equal(t, want, got)
assert.Equal(t, want, got)
})

t.Run("test doc templaing using artifact config", func(t *testing.T) {
t.Parallel()
w := &specWrapper{Spec: &dalec.Spec{
Name: "test-pkg",
Artifacts: dalec.Artifacts{
Docs: map[string]dalec.ArtifactConfig{
"README.md": {
SubPath: "docs",
Name: "README",
},
},
},
}}

got := w.Files().String()
want := `%files
%doc %{_docdir}/test-pkg/docs/README
`
assert.Equal(t, want, got)
})

t.Run("test doc templaing using defaults", func(t *testing.T) {
t.Parallel()
w := &specWrapper{Spec: &dalec.Spec{
Name: "test-pkg",
Artifacts: dalec.Artifacts{
Docs: map[string]dalec.ArtifactConfig{
"README.md": {},
},
},
}}

got := w.Files().String()
want := `%files
%doc %{_docdir}/test-pkg/README.md
`
assert.Equal(t, want, got)
})

t.Run("test doc templaing using defaults and longer path", func(t *testing.T) {
t.Parallel()
w := &specWrapper{Spec: &dalec.Spec{
Name: "test-pkg",
Artifacts: dalec.Artifacts{
Docs: map[string]dalec.ArtifactConfig{
"/some/path/to/README.md": {},
},
},
}}

got := w.Files().String()
want := `%files
%doc %{_docdir}/test-pkg/README.md
`
assert.Equal(t, want, got)
})

t.Run("test license templaing using defaults", func(t *testing.T) {
t.Parallel()
w := &specWrapper{Spec: &dalec.Spec{
Name: "test-pkg",
Artifacts: dalec.Artifacts{
Licenses: map[string]dalec.ArtifactConfig{
"LICENSE": {},
},
},
}}

got := w.Files().String()
want := `%files
%license %{_licensedir}/test-pkg/LICENSE
`
assert.Equal(t, want, got)
})

t.Run("test license templaing using ArtifactConfig", func(t *testing.T) {
t.Parallel()
w := &specWrapper{Spec: &dalec.Spec{
Name: "test-pkg",
Artifacts: dalec.Artifacts{
Licenses: map[string]dalec.ArtifactConfig{
"LICENSE": {
Name: "LICENSE.md",
SubPath: "licenses",
},
},
},
}}

got := w.Files().String()
want := `%files
%license %{_licensedir}/test-pkg/licenses/LICENSE.md
`
assert.Equal(t, want, got)
})
}

0 comments on commit ebf08e6

Please sign in to comment.